java/6519: Empty Strings cannot always be optimized away

mark@klomp.org mark@klomp.org
Tue Apr 30 12:56:00 GMT 2002


>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:



More information about the Gcc-prs mailing list