[cdi-dev] [JBoss JIRA] (CDI-740) Proxy fields can be accessed if they are protected or package private
Matej Novotny (Jira)
issues at jboss.org
Thu Nov 29 08:14:00 EST 2018
[ https://issues.jboss.org/browse/CDI-740?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13667996#comment-13667996 ]
Matej Novotny commented on CDI-740:
-----------------------------------
This is a known limitation. You are only safe in directly accessing beans when the scope is dependent.
Soon as there is a client proxy in play, you need to use methods which will delegate to actual bean instance in the context (as opposed to proxy itself which is a different object - which is why you still see 0 there).
Related issues CDI-446 and CDI-244
> 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