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.

Enforce validation of return type of observer methods

See original GitHub issue

Currently, CDI doesn’t mandate that OM have certain return type. However, since those methods are invoked by CDI, user has no means to obtain whatever return type/value it has. It might be worth considering to enforce that the return type is void through validation.

Note that in theory, CDI doesn’t prohibit users from invoking these methods manually. Due to this, it would be potentially breaking change as some application might be using that. Though all parameters (except event param OFC) of OM are injection points so manual invocation IMO makes little sense.

The only impact of this issue for CDI would be enforcing good practices in CDI applications.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Ladicekcommented, Nov 22, 2022

The specific context we had in mind is programmers declaring asynchronous observers that return CompletionStage<Void> or similar asynchronous types. To a lot of users, that gives the impression that the CDI container will wait for the completion stage to complete before returning from fireAsyncwill arrange the CompletionStage returned from fireAsync to only complete once the CompletionStages returned from the observers complete, which is not the case. My intuitive reaction to that was: we should treat non-void observer methods as definition errors (and I was surprised that the spec doesn’t mandate that).

We discussed this issue on the CDI call today and didn’t really reach any conclusion AFAICT. I’m tempted to propose that we just close this, citing Hyrum’s Law as the main reason 😃

0reactions
Ladicekcommented, Nov 24, 2022

That’s a very creative combination of interceptors and observers indeed. The specification says that observer method invocations are business method invocations and hence are intercepted, so it seems perfectly valid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation Observer - VeeValidate
Validating before submit is even easier than the old way, using the public methods and a simple ref we can validate all providers...
Read more >
java - Validating data - Stack Overflow
There are multiple ways to do this. One is like you said. Let validate() returns a boolean and keep a Set of errors...
Read more >
LiveData overview - Android Developers
LiveData follows the observer pattern. LiveData notifies Observer objects when underlying data changes. You can consolidate your code to update ...
Read more >
Using Traitlets — traitlets 5.7.1 documentation - Read the Docs
Traitlets perform some validation and allow coercion of new trait values on ... When observers are methods of the class, a decorator syntax...
Read more >
21.3 Validating Constructors and Methods - Java Platform ...
To validate the return value for a method, you can apply constraints directly to the method or constructor declaration. @NotNull public Employee getEmployee()...
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