java/1328: Definate assignment with switch
bryce@albatross.co.nz
bryce@albatross.co.nz
Wed Dec 20 12:24:00 GMT 2000
>Number: 1328
>Category: java
>Synopsis: Definate assignment with switch
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: apbianco
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Dec 20 12:19:04 PST 2000
>Closed-Date:
>Last-Modified: Sun Dec 10 16:16:00 PST 2000
>Originator: Bryce McKinlay
>Release: unknown-1.0
>Organization:
>Environment:
any
>Description:
The following example is illegal because 'r' may not have
been assigned when it is concatenated. gcj does not pick
up this error.
public class Definate
{
int id = 2;
void a()
{
String r;
switch (id)
{
case 99:
r = "foo";
break;
}
r += "bar";
}
}
>How-To-Repeat:
Compile the example above.
>Fix:
>Release-Note:
>Audit-Trail:
Formerly PR gcj/304
From: Bryce McKinlay <bryce@albatross.co.nz>
To: java-gnats@sourceware.cygnus.com
Cc:
Subject: Re: gcj/304: Definate assignment with switch
Date: Mon, 11 Dec 2000 13:09:01 +1300
bryce@albatross.co.nz wrote:
> The following example is illegal because 'r' may not have
> been assigned when it is concatenated. gcj does not pick
> up this error.
Here's another similar situation where gcj fails to report a
lack-of-definate-assignment error:
public class DefinateAssign
{
DefinateAssign next;
public Object a()
{
DefinateAssign e;
if (next != null)
e = next;
if (e == null)
{
e = new DefinateAssign();
}
return e;
}
}
In this case "e" can end up being a garbage pointer, which will cause
weird crashes elsewhere. I got tripped up by this badly, guess I
should have tried to compile with jikes ;-)
[ bryce ]
>Unformatted:
More information about the Gcc-prs
mailing list