This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
java/6519: Empty Strings cannot always be optimized away
- From: mark at klomp dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 30 Apr 2002 19:49:45 -0000
- Subject: java/6519: Empty Strings cannot always be optimized away
- Reply-to: mark at klomp dot org
>Number: 6519
>Category: java
>Synopsis: Empty Strings cannot always be optimized away
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Apr 30 12:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: mark@klomp.org
>Release: gcj 3.1
>Organization:
>Environment:
>Description:
The following program returns false, but should return true:
public class SN
{
public static void main(String[] args)
{
System.out.println("null".equals(n(0) + ""));
}
static String n(int i)
{
if (i==0) return null; else return "x";
}
}
The problem is that the String concatenation gets optimized away and
since n(0) returns null it does not generate the string "null" but it
generates the value null. The problem disappears when the return type of
n() is changed to Object.
It is also responsible for the following Mauve test failure:
FAIL: gnu.testlet.java.lang.StringBuffer.plus (number 1)
>How-To-Repeat:
>Fix:
See the following patch:
http://gcc.gnu.org/ml/gcc-patches/2002-04/msg01019.html
>Release-Note:
>Audit-Trail:
>Unformatted: