[cdi-dev] [JBoss JIRA] (CDI-740) Proxy fields can be accessed if they are protected or package private

Frigo Coder (Jira) issues at jboss.org
Mon Dec 3 04:05:00 EST 2018


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

Frigo Coder commented on CDI-740:
---------------------------------

I do recognize that we are accessing an uninitialized field of a proxy object. Weld does refuse to start if the field in question is public. But not for protected and package private fields, they are silently ignored. Is this intentional, are there any valid uses cases for them, or is it just an oversight?

> Proxy fields can be accessed if they are protected or package private
> ---------------------------------------------------------------------
>
>                 Key: CDI-740
>                 URL: https://issues.jboss.org/browse/CDI-740
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Beans, Contexts, Java EE integration
>         Environment: IBM WebSphere Liberty, Java EE 7.0 Full Platform
>            Reporter: Frigo Coder
>            Priority: Major
>
> CDI detects and rejects proxyable beans if they expose a public field. However protected and package private fields are silently accepted. In the following example the method returns 0 instead of the correct value of 8:
> {code:java}
> @ApplicationScoped
> public class Car {
>     @Inject
>     private Engine engine;
>     public int numberOfEngineCylinders() {
>         return engine.cylinders;
>     }
> }
> @RequestScoped
> public class Engine {
>     protected int cylinders;
>     @PostConstruct
>     public void init() {
>         cylinders = 8;
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v7.12.1#712002)


More information about the cdi-dev mailing list