question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refuse to use a decorating `Client` and `Service` if `as()` or `serviceAdded()` is not overriden.

See original GitHub issue

A common mistake a user makes when writing a decorator is:

ServerBuilder sb = new ServerBuilder();
sb.service("/svc", myService.decorate(delegate -> (ctx, req) -> {
    ...
    return delegate.serve(ctx, req);
}));

The above decorator is not correct because the returned service does not override the default as() and serviceAdded() implementation. A correct usage is:

sb.service("/svc", myService.decorate((delegate, ctx, req) -> {
    return delegate.serve(ctx, req);
});
// or
sb.service("/svc", myService.decorate(delegate -> new SimpleDecoratingService(delegate) {
    ...
    return delegate().serve(ctx, req);
    ...
}));

We can detect such a mistake by checking if the decorator overrides the default as() and serviceAdded() implementation using Java reflection API and raise an exception.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
trustincommented, Feb 18, 2020

🤣 Yes, please!

2reactions
ikhooncommented, Feb 18, 2020

I’m not trustin, but I could tell “Yes, please!” 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing With Clients Who Refuse To Pay - Smashing Magazine
Cons # If you are dealing with a client who is already refusing to pay for completed work, chances are that this respectful...
Read more >
Dependency Injection error: Unable to resolve service for type ...
NET Core MVC application and use Dependency Injection and Repository Pattern to inject a repository to my controller. However, I am getting an...
Read more >
Nonattest Services Frequently Asked Questions and Answers
and scope of the nonattest service. Overseeing the service does not require that the individual designated by the attest client must supervise the...
Read more >
Publication 35, Interior Designers and Decorators - CDTFA
This publication is intended as a general guide to the Sales and Use Tax Law and Regulations as they apply to interior designers...
Read more >
Fix Packs Available for IBM API Connect v2018.x
List of fix packs for IBM API Connect v2018.x.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found