Bug 16839 - Final vars in switch generate compile error in anonymous class.
Summary: Final vars in switch generate compile error in anonymous class.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on: 28067
Blocks:
  Show dependency treegraph
 
Reported: 2004-07-30 22:24 UTC by Becky Andersen
Modified: 2007-01-09 20:46 UTC (History)
3 users (show)

See Also:
Host: Win2K
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-02 01:01:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Becky Andersen 2004-07-30 22:24:50 UTC
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.
Comment 1 Tom Tromey 2004-07-31 16:10:11 UTC
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).
Comment 2 Becky Andersen 2005-01-01 20:11:16 UTC
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/

Comment 3 Andrew Pinski 2005-01-01 20:17:07 UTC
(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.
Comment 4 Tom Tromey 2007-01-09 20:46:24 UTC
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.