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

Allow public static fields on managed beans which declare any other scope than dependent

XMLWordPrintable

    • Icon: Clarification Clarification
    • Resolution: Done
    • Icon: Major Major
    • 1.1.PRD
    • None
    • None
    • None

      See 3.1. Managed beans:

      If a managed bean has a public field, it must have scope @Dependent. If a managed bean with a public field declares any scope other than @Dependent, the container automatically detects the problem and treats it as a definition error.

      I see no reason why to disallow public static fields on normal scoped beans. To treat public non-static fields as a definition error due to proxy generation is reasonable. However public static fields are usually referenced by the class name and refering to static fields with an object reference (proxy in this case) is discouraged. Moreover, protected and package-private fields which might also cause confusion around proxies are allowed.

      BTW Weld allows public static fields on normal scoped beans at the moment.

      Maybe the spec wording could be:

      3.1. Managed beans
      If a managed bean has a non-static public field, it must have scope @Dependent. If a managed bean with a non-static public field declares any scope other than @Dependent, the container automatically detects the problem and treats it as a definition error.

              pmuiratbleepbleep Pete Muir (Inactive)
              mkouba@redhat.com Martin Kouba
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: