Enforce validation of return type of observer methods
See original GitHub issueCurrently, 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:
- Created 10 months ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 containerwill wait for the completion stage to complete before returning fromwill arrange thefireAsync
CompletionStage
returned fromfireAsync
to only complete once theCompletionStage
s 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 😃
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.