Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-740

Proxy fields can be accessed if they are protected or package private

    Details

    • Steps to Reproduce:
      Hide
      • Create a @RequestScoped bean
      • Add a protected or package private field
      • Inject the bean into another bean with different context
      • Access the field, it will come from the proxy object
      • Value will not be initialized and incorrect
      Show
      Create a @RequestScoped bean Add a protected or package private field Inject the bean into another bean with different context Access the field, it will come from the proxy object Value will not be initialized and incorrect

      Description

      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:

      @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;
          }
      
      }
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                frigocoder Frigo Coder
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: