JDK-8034044 : Class.getModifiers() returns "static" for anonymous classes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 7u4
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-02-09
  • Updated: 2017-07-19
  • Resolved: 2014-04-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
9 b08Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8184946 :  
 Oracle's implementation returns "static" for anonymous classes, which 
contradicts the spec.

Java 7 spec: 
        An anonymous class is always implicitly final ( 
        An anonymous class is always an inner class (8.1.3); it is never 
static (8.1.1, 8.5.1). 
        The modifier static pertains only to member classes (8.5.1), not to 
top level or local or anonymous classes. 

Review thread: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-March/008581.html

I recommend the related bugs linked to be investigated to get the history of how and why the modifiers of anonymous classes are set the way they are.

The reported testcase: TESTCASE -------- import java.lang.reflect.Modifier; public class ModTest { public static void main(String[] args) { Object o = new Object() {}; System.out.println("Class.toString(): " + o.getClass().toString()); System.out.println("Class.getModifiers(): " + o.getClass().getModifiers() + " = " + Modifier.toString(o.getClass().getModifiers())); } } REPRODUCTION INSTRUCTIONS ------------------------- 1. javac ModTest.java 2. javap ModTest$1 (Note the "final" modifier in the javap output) 3. java ModTest (Note the "static" modifier returned by Class.getModifiers())