Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8161013

Never treat anonymous classes as 'final'

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u60, 9
    • Fix Version/s: 9
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b128
    • Verification:
      Verified

      Description

      Per JDK-8161009, an assertion in JLS that anonymous classes are 'final' is incorrect, due to inconsistency with longstanding behavior. Anonymous classes should not be considered 'final'.

      javac generally does not do so, but there are two bugs:
      - In an attempt to conform to the old JLS without fully doing so, JDK-6219964 and JDK-6520152 set the 'final' flag during checking, then unset it. Wanted behavior is to simply leave it unset.
      - The logic to unset ACC_FINAL during code gen accidentally leaves it set on 'access_flags' (but not 'inner_class_access_flags') for anonymous classes in static contexts.

      Example of the first bug:

          interface I {}
          
          Object o = new Object() {
              I i = (I) this; // expected: ok; actual: cast error
          };

      Example of the second bug:

          class C {
              static Object o = new Object() {};
          }

          javac C.java
          javap -verbose C\$1

          final class C$1 <--- expected: not 'final'
            minor version: 0
            major version: 52
            flags: ACC_FINAL, ACC_SUPER <--- expected: not ACC_FINAL
          ...
          InnerClasses:
               static #2; //class C$1 <--- as expected: not 'final'

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: