[cdi-dev] [JBoss JIRA] (CDI-456) fix Bean#getBeanClass() definition

Anatole Tresch (JIRA) issues at jboss.org
Fri Sep 5 16:01:05 EDT 2014


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

Anatole Tresch commented on CDI-456:
------------------------------------

Jozef, imagine the following

{noformat}
public class MyProducer{
@Produces @ApplicationScoped
  public MyBean create(){ return new MyBean(); }
}
{noformat}

The {{MyBean}} class is declared in the *ear*, as follows:

{noformat}
public final class MyBean{
     public final String CONTEXT = Thread.currentThread().getContextClassLoader().toString();
}
{noformat}

Now you have 3 wars, the class instance for {{MyBean}} will be the same for all three wars, since it is loaded from the *ear classloader* (but also visible to the war classloader).
Nevertheless, since the {{MyProducer}} producer class is defined on *war level*, you get three different instances, each with a different {{CONTEXT}}...


> fix Bean#getBeanClass() definition
> ----------------------------------
>
>                 Key: CDI-456
>                 URL: https://issues.jboss.org/browse/CDI-456
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Beans
>            Reporter: Mark Struberg
>
> currently Bean#getBeanClass() is defined to return the class of the bean it produces but has one important exception: in case of a producer method or field it must return the class of the owner bean of this method or field.
> Imo this only causes troubles and doesn't add any benefit. 
> * At the time when 'using' the Bean (create and destroy) we always ONLY need the type which is to be created.
> * At the time we create interceptors we ONLY need the type which is to be created;
> * At the time we create the normalscoping proxies we ONLY need the type which is to be created;
> In fact the only time we need the ownerBean is when scanning the methods and fields in it. And for creating we really need the owner-Bean and not it's bean-class!
> In OWB we worked around this by having our own method getReturnType() which consistently returns the type which gets created.



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the cdi-dev mailing list