Community
Participate
Working Groups
According to the java language spec (section 13.1), an anonymous class inside an anonymous class should be named Foo$n$n, not Foo$n as is done by the eclipse compiler (the class name should be the *immediately* enclosing class, $, number). This causes Class.getSimpleName() to throw an exception, which can cause all kinds of interesting problems in logging and debugging code. <pre> public class EclipseBug { public static void main(String[] s) { new Object() { { new Object() { { System.out.println(this.getClass().getName()); System.out.println(this.getClass().getSimpleName()); } }; } }; } } //</pre> /ibs/bin$ java EclipseBug common.EclipseBug$2 Exception in thread "main" java.lang.InternalError: Malformed class name at java.lang.Class.getSimpleName(Class.java:1129) at common.EclipseBug$2.<init>(EclipseBug.java:10) at common.EclipseBug$1.<init>(EclipseBug.java:7) at common.EclipseBug.<clinit>(EclipseBug.java:5) Whereas compiled with javac, the result is /Users/alf/temp$ java EclipseBug EclipseBug$1$1 (getSimpleName() returns a blank string)
This is true only if the compliance is 1.5. Below 1.5, the actual naming is fine.
Created attachment 27697 [details] Proposed fix
Proposed fix looks good.
Added ComplianceTest_13/_14/_15#test102. Fixed
*** Bug 114266 has been marked as a duplicate of this bug. ***
Verified for 3.1.2 in M20060109-0800.
Verified for 3.2M4 in I20051215-1506