Details
-
Bug
-
Resolution: Fixed
-
P4
-
8u60, 9
-
b128
-
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'
javac generally does not do so, but there are two bugs:
- In an attempt to conform to the old JLS without fully doing so,
- 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
- relates to
-
JDK-8162946 Casting 'this' from anonymous class to arbitrary interface succeeds
- Resolved
-
JDK-6520152 ACC_FINAL flag for anonymous classes shouldn't be set
- Closed
-
JDK-6219964 Compiler allows illegal cast of anonymous inner class
- Closed
-
JDK-8161009 15.9.5: Anonymous classes aren't actually 'final'
- Closed