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

Jozef Hartinger (JIRA) issues at jboss.org
Fri Sep 5 03:25:02 EDT 2014

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

Jozef Hartinger commented on CDI-456:

{quote}Using beanClass and classloader is not portable at all and even if EE containers can surely deal with it, in SE and OSGi worlds it will be very fragile.{quote}

No matter what environment you are running, if you have class A and class B in Java you can always tell if A's ClassLoader can see B or not. No matter if it's OSGi, an EE container that does or does not isolate modules, a plain flat SE classpath or something completely different, you can always determine this.

What CDI should do is to behave the same and make A injectable to B as long as A is visible from B or in other words if you can do new A() within B. That is the only sane way to define accesibility in CDI - to follow ClassLoader accesibility.

> 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

More information about the cdi-dev mailing list