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

Jozef Hartinger (JIRA) issues at jboss.org
Mon Sep 8 04:07:00 EDT 2014


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

Jozef Hartinger commented on CDI-456:
-------------------------------------

{quote}Bean#getBeanClass() is only defined for 'Managed Beans' at the moment. That means it is only defined for classes which get scanned at boot time. It is not defined for anything you do via Extensions.{quote}

The Javadoc defines {{Bean#getBeanClass()}} for *managed beans, session beans, producer methods and producer fields*. Not just managed beans. In addition, although {{Bean#getBeanClass()}} is not explicitly defined for custom beans, the expected behavior can be implied from sections 5.1, 5.1.1.2 and 5.1.4. The behavior for custom beans should be defined more explicitly as currently it needs to be implied and is not immediately obvious.

{quote} it wont work for 3 custom Bean<T> which are differently configured for each of the 3 WARs{quote}
See my example above. It works there.

{quote}Especially since getBeanClass() might return null if you strictly follow the spec wording.{quote}
{quote}For a custom implementation of the Bean interface defined in Section 11.1, “The Bean interface”, the container calls getBeanClass() to determine the bean class of the bean{quote}

Since 'bean class' is used in 5.1.4. to determine if the bean is available for injection then returning null from {{getBeanClass}} is arguably a definition error.

> 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