This valid java code generates a compile error. public class finaltest { public void main(String args[]) { System.out.println("got to main"); switch(23) { case 1: final String s = "x"; break; case 2: new Runnable() { public void run() { System.out.println("run"); } }; break; } } } C:\> \app\gcj\gcc-3.5\bin\gcj finaltest.java finaltest.java: In class `finaltest': finaltest.java: In method `finaltest.main(java.lang.String[])': finaltest.java:13: error: Variable `s' may not have been initialized. }; ^ 1 error C:\> gcj --version gcj (GCC) 3.5.0 20040629 (experimental) Copyright (C) 2004 Free Software Foundation, Inc.
I believe the bug here is that gcj captures all final local variables in an anonymous class constructor, whether or not those variables are used by the class. This means that "s" appears to be used by the "new" invocation, causing the definite assignment code to emit an error (which would be correct if the anonymous class actually had a use of the variable).
Subject: RE: Final vars in switch generate compile error in anonymous cl This email makes absolutely no sense. What information is this message trying to tell me? Does anyone even know the difference between information and data anymore? >From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> >Reply-To: gcc-bugzilla@gcc.gnu.org >To: beandz@hotmail.com >Subject: [Bug java/16839] Final vars in switch generate compile error in >anonymous class. >Date: 27 Dec 2004 14:45:29 -0000 >Received: from sourceware.org ([12.107.209.250]) by mc2-f4.hotmail.com with >Microsoft SMTPSVC(6.0.3790.211); Mon, 27 Dec 2004 06:45:29 -0800 >Received: (qmail 2963 invoked by uid 48); 27 Dec 2004 14:45:29 -0000 >X-Message-Info: JGTYoYF78jG64Tc3+JdzXvoH9oufkYYVLa15fltp7OY= >References: <20040730222448.16839.beandz@hotmail.com> >X-Bugzilla-Reason: Reporter >Return-Path: dberlin@gcc.gnu.org >X-OriginalArrivalTime: 27 Dec 2004 14:45:29.0427 (UTC) >FILETIME=[B5ACF230:01C4EC22] > >-- > What |Removed |Added >---------------------------------------------------------------------------- > Keywords| |rejects-valid > Last reconfirmed|2004-07-31 16:10:13 |2004-12-27 14:45:29 > date| | > > >http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16839 > >------- You are receiving this mail because: ------- >You reported the bug, or are watching the reporter. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
(In reply to comment #2) > Subject: RE: Final vars in switch generate compile error in anonymous cl > > This email makes absolutely no sense. What information is this message > trying to tell me? Does anyone even know the difference between information > and data anymore? Nothing, I was adding a keyword so we can keep track of different kinds of bugs. Also I was reconfirming the bug so we know that it is still a bug in the latested CVS version of gcj.
All gcj front end bugs have been fixed by the gcj-eclipse branch merge. I'm mass-closing the affected PRs. If you believe one of these was closed in error, please reopen it with a note explaining why. Thanks.