JDK-8060012 : Class.isAnonymousClass() returns false when class major number is 48.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8u20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-10-02
  • Updated: 2016-07-28
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.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux debian 3.14-2-amd64 #1 SMP Debian 3.14.15-2 (2014-08-09) x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Consider the following Java class:

public class A {                                                                                                                                                                               
  public static void main(String[] argv) {
    Object o = new Object () {
      public String toString() {
        return "abcd";
      }   
    };  
    System.out.println("obj is: "+ o.toString());

  }
}

You can compile it with:
$ javac A.java
in which case the major number of the class will be 51 or 51

Or with
$ javac -source 1.4 -target 1.4 A.java
in which case the major number of the class will be 48

Then consider the following class:
public class Check {
  public static void main(String[] args) {
    boolean b = A$1.class.isAnonymousClass();  
    System.out.println("isAnonymous: "+ b);
  }
}

isAnonymousClass() returns true, as expected, when the major version of the A$1 class is 51 or 52.
However, it returns false when the major version of class A$1 is 48 which is wrong.
There may be some subtleties with major version numbers. If so, please redirect me to the text in the specifications describing this.





STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See Description.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class.isAnonymousClass() should have returned true.
ACTUAL -
Class.isAnonymousClass() returned false on an anonymous class.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See description.
---------- END SOURCE ----------


Comments
The isAnonymousClass method, and several other methods introduced in JDK 5 (JDK-4992173), rely on information present in 49.0 and higher class files. That is, information present in -target 5 and higher. In JDK 9, javac has dropped for -source and -target values earlier than 6. I recommend using a class file version newer than 48.0.
09-10-2014

Tested with JDK 1.4.2, 7u67 and 8u20. isAnonymousClass() returns true, as expected, when the major version of the A$1 class is 51 or 52. However, it returns false when the major version of class A$1 is 48 (JDK 1.4) which is wrong. 48 is the major number for JDK version 1.4 and 51 and 52 belongs to JDK 7 an JDK 8. Keeping it open for further evaluation as not sure if this is an issue with old JDK 1.4.2?
09-10-2014

Verified on the version below on Windows 7. java version "1.7.0_55" Java(TM) SE Runtime Environment (build 1.7.0_55-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode) When major version is 51.0, output is isAnonymous: true When major version is 48.0, output is isAnonymous: false
08-10-2014