[cdi-dev] [JBoss JIRA] (CDI-721) configureAnnotatedType vs setAnnotatedType restrition is unecessarily strict

Matej Novotny (JIRA) issues at jboss.org
Thu Jan 25 04:10:00 EST 2018


    [ https://issues.jboss.org/browse/CDI-721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13523558#comment-13523558 ] 

Matej Novotny commented on CDI-721:
-----------------------------------

To underline it, this is about invoking the {{set}} and {{configure}} methods _within one observer invocation_.
Across multiple methods (be it in one or multiple extensions) you can do as you please even now.

To me this restriction seems OK and I think we should not remove it. While the reason behind it might not be technical, it enforces clearer code.
There is no reason known to me where you (*within one method*) need to start configuring the object (say AT for now) and then you suddenly change you mind and call the {{setAT}} method and replace it altogether. That means the previous configuration was a waste of time and resources because you just tossed it away. Not to mention it is easy to refactor your code not to invoke both methods and first check what is it you want to do with that given AT.

Therefore most people who write 'sane code' would not even bump into this and the rest will at least realize they are doing some extraneous work.
We have yet to see a case where this restriction would block user from achieving something.

> configureAnnotatedType vs setAnnotatedType restrition is unecessarily strict
> ----------------------------------------------------------------------------
>
>                 Key: CDI-721
>                 URL: https://issues.jboss.org/browse/CDI-721
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Portable Extensions
>    Affects Versions: 2.0 .Final
>            Reporter: Mark Struberg
>
> {noformat}
> Any observer of this event is permitted to wrap and/or replace the AnnotatedType by calling either setAnnotatedType() or configureAnnotatedType(). If both methods are called within an observer notification an IllegalStateException is thrown.
> {noformat}
> This rule is way too strict without any real reason.
> Any CDI container must support that both methods are being called on the same event payload anyway. Because we did not forbid that observerMethod1 invokes setAnnotatedType and observerMethod2 uses configureAnnoatedType. And that's good that way, otherwise the pluggability would be lost.
> We should delete this sentence without any substitution.
> The same applies to similar configurator methods like configureBeanAttributes, etc.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the cdi-dev mailing list