JDK-8130032 : Anonymous inner class is not final
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u45,8u60,9
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-06-26
  • Updated: 2015-06-29
  • Resolved: 2015-06-29
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The Java compiler does not add "final" modifier to anonymous inner class whereas 15.9.5 of JLS requires this.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the code from "Source code" field; check the console ouput.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class is final: true
ACTUAL -
Class is final: false

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.reflect.Modifier;

public class TestClass {
    public static void main(String args[]) {
        Object o = new Object() { };
        System.out.println("Class is final: " + Modifier.isFinal(o.getClass().getModifiers()));
    }
}

---------- END SOURCE ----------


Comments
According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html 15.9.5. Anonymous Class Declarations: - An anonymous class is always an inner class (��8.1.3); it is never static (��8.1.1, ��8.5.1). ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1. Run the attached test code (TestClass.java) in Windows 7. 2. Checked this for JDK 8, 8u45, 8u60 ea b19, and 9 ea b69. 8: FAIL 8u45: FAIL 8u60 ea b19: FAIL 9 ea b69: FAIL 3. Output with JDK 8u45: $ java TestClass Class is final: false 4. Conclusion: Based upon above, this issue is reproducible with JDK 8-all and 9 ea as reported by the submitter. Moving this up for further evaluation. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29-06-2015