Summary: | [compiler] Incorrect/confusing error message on inner class static field declaration | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Deepak Azad <deepakazad> | ||||
Component: | Core | Assignee: | Ayushman Jain <amj87.iitr> | ||||
Status: | VERIFIED FIXED | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | amj87.iitr, Olivier_Thomann, sptaszkiewicz, srikanth_sankaran | ||||
Version: | 3.7 | Flags: | srikanth_sankaran:
review+
|
||||
Target Milestone: | 3.8 M3 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Deepak Azad
2011-04-21 02:50:22 EDT
Note that javac 1.7 warns "modifier 'static' is only allowed in constant variable declarations". This will need a new error message, hence deferring to 3.8 Static fields initialized with a constant expressions are fine. The error message should reflect that. Created attachment 204279 [details]
proposed fix
Corrects the error message to say "The field {0} cannot be declared static in a non-static inner type, unless initialized with a constant expression". Updated tests
Srikanth, does the new diagnostic look ok? (In reply to comment #4) > Srikanth, does the new diagnostic look ok? Apologize for the delay, Ayush. Agree that the modified diagnostic is clearer and consistent with javac. For the record, javac also seems have to revised the message at JDK7 timeframe. Released in HEAD for 3.8M3 via commit 3b4463c1006c09cac09c3007a035ccb5f09314da Verified for 3.8 M3 using build id: N20111022-2000. Raised Bug 361771 as follow up. (In reply to comment #7) > Verified for 3.8 M3 using build id: N20111022-2000. > Raised Bug 361771 as follow up. That turned out to be a dup of bug 343420 Now I see an issue with: public class X { public static void main(String[] args) { class Local { private static final long CONSTANT = 1L; // code select fails static int x = 10; } new X() { private static final long FINAL = 1L; // code select fails }; } } we complain: The field x cannot be declared static in a non-static inner type, unless initialized with a constant. It is being with a constant after all. We could do: The field x cannot be declared static in a non-static inner type, unless also final ? (In reply to comment #9) > The field x cannot be declared static in a non-static inner type, > unless also final ? But this would sound ambiguous for the error case shown in comment 0, where all fields are static and final javac says "modifier 'static' is only allowed in constant variable declarations". This sounds more generic for both of the above cases. So maybe we should also fine-tune the message to say "The field {0} cannot be declared static in a non-static inner type, unless it is final and initialized with a constant expression". Too wordy? (In reply to comment #10) > (In reply to comment #9) > > The field x cannot be declared static in a non-static inner type, > > unless also final ? > But this would sound ambiguous for the error case shown in comment 0, where all > fields are static and final Mmmh. > > javac says "modifier 'static' is only allowed in constant variable > declarations". Isn't "constant variable" oxymoronic ? :) How about "The field x cannot be declared static in a non-static inner type as it is not a constant" |