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

Martin Kouba (JIRA) issues at jboss.org
Thu Jan 25 03:07:00 EST 2018


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

Martin Kouba commented on CDI-721:
----------------------------------

Well, I don't think we should remove this restriction. The reason was to simplify the contract and avoid possible confusion (see also CDI-596). Note that the result of configurator should replace the original one at the end of the observer invocation (there is no terminal operation in configurator API).

E.g. in this example:
{code:java}
void observePat(@Observes ProcessAnnotatedType<Foo> event) {
  event.configureAnnotatedType().add(RequestScoped.Literal.INSTANCE);
  event.setAnnotatedType(new FooAnnotatedType());
}
{code}
The configurator must be discarded completely. So we would have to change the wording of {{ProcessAnnotatedType.configureAnnotatedType()}} too. Something like _"... configurator AnnotatedType will replace the original one at the end of the observer invocation or when setAnnotatedType() is called..."_. 

Anyway, I don't see a benefit in allowing both methods to be called within a single observer method invocation.

> 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