This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java/6519: Empty Strings cannot always be optimized away



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]