Community
Participate
Working Groups
I'm not sure whether this is a bug of Eclipse or javac. However, I found that javac 1.4.2_01 and Eclipse 3.0M3 compile the attached code differently and one compiler should be wrong (or the Java language spec is ambiguous). I'd say Eclipse is right but just to make sure, I created this bug. When compiled with javac, the code emits "null", when compiled with Eclipse, the code emits a DataFlavor instance. Please notice the somewhat recursive initialization sequence.
Created attachment 6059 [details] InitializerBug.java
I forgot, I'm using the default 1.3 Compiler compliance level with default 1.1 .class file compatibility. I used no -source or -target options on javac.
This is another example of bug 37565. Sun compiler initializes the class when the class literal is used. In your example, B.class initializes the class B, but at this moment f is not initialized yet. Eclipse compiler follows the JLS and doesn't initialize the class B when B.class is called. Then B will be initialized when B.fs[0] is called and at this moment, f is initialized in the class InitializerBug. Close as duplicate of bug 37565. *** This bug has been marked as a duplicate of 37565 ***