Community
Participate
Working Groups
public class StaticInitBug { public static final int STATIC_INT; static { // Bug(?): Complies on Eclispe M7: STATIC_INT =StaticInitBug.STATIC_INT; // Don't compile (if uncommented) on Eclipse M7 (as expected) // STATIC_INT =STATIC_INT; } }
See http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37544. Points 8.3.2 and 8.3.2.1. Note that javac has exactly the same behavior. Close as INVALID.
You are right, javac behaves the same way. But: if this is the right behaviour (and I can't believe that it is), then the question is: Which value has STATIC_INT after a successfull initialization of the class? I think that is not defined in the JLS, perhaps javac has the same bug?
StaticInitBug.STATIC_INT is reflecting int field default value: 0.
That is what I expected, but it is not the answer of my Question ;-) I assume you used Java's Reflection API to detect that, or your knowlegde about your compiler. But how is it defined in the JLS? I believe it is not defined! But one the other hand is defined that a "definite assignment" should init the static final field. So if the static-clause in the example is real valid, then there is a very small and perhaps unintended gap in the JLS. What do you think?
The JLS is often fuzzy, and requires some interpretation in order to implement corner cases. Remember though we don't own it... See more information at: http://www.ergnosis.com/java-spec-report/java-language/jls-16-c.html
Thank you very much for your answer, the link is really interessting. I learned there that it is much more compilcated to write a compiler as I thought! I will read there before I write my next compiler "bug" report. BTW: Good luck with your 1.5 compiler!