[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 12:09:00 EST 2018


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

Frigo Coder edited comment on CDI-740 at 12/3/18 12:08 PM:
-----------------------------------------------------------

{quote}Does it even make sense to ask this? Accessing fields directly is undesirable as a (java) practice in the first place...{quote}

Data classes with public fields would make sense. Protected and package private fields make much less sense, I still managed to trip myself up with them, can not remember the exact situation though. I sometimes wish Java had properties instead of fields so that proxying would work seamlessly.

{quote}Anyway, I have no idea if it was intentional back when it was specified this way but adjusting it now will cause backward compat. problems as now working applications would suddenly crash during bootstrap.{quote}

Fair point, thank you for at least considering it. I think I will still try to create a CDI extension to check for these cases in our project, I would like to be certain and we have no such compatibility issues.


was (Author: frigocoder):
> Does it even make sense to ask this? Accessing fields directly is undesirable as a (java) practice in the first place...

Data classes with public fields would make sense. Protected and package private fields make much less sense, I still managed to trip myself up with them, can not remember the exact situation though. I sometimes wish Java had properties instead of fields so that proxying would work seamlessly.

> Anyway, I have no idea if it was intentional back when it was specified this way but adjusting it now will cause backward compat. problems as now working applications would suddenly crash during bootstrap.

Fair point, thank you for at least considering it. I think I will still try to create a CDI extension to check for these cases in our project, I would like to be certain and we have no such compatibility issues.

> 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