United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7009359 HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
JDK-7009359 : HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected

Details
Type:
Bug
Submit Date:
2010-12-28
Status:
Closed
Updated Date:
2013-02-11
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
hs20 (b06)

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

Description
StringBuffer should throw NPE when invoked with null however with  -XX:+AggressiveOpts it substitute null instead.

Here is example.
class TSB {
    public static void main (String[] args) {
        while(true) {
            System.out.println(stringmakerBUG());
        }
    }

    public static String stringmakerBUG() {
       try {
           return new StringBuffer(null).toString();
       } catch (NullPointerException e) {
           return "NPE";
       }
    }
}

run:
java  -server -XX:+AggressiveOpts TSB

                                    

Comments
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/2ddb2fab82cb
                                     
2010-12-29
PUBLIC COMMENTS

Igor pointed me that null could be passed as argument so its value
will be not known during compilation.

Added null check with uncommon trap but using special Reason_intrinsic.
The test is updated to pass null as argument.

http://cr.openjdk.java.net/~kvn/7009359/webrev.01

Thanks,
Vladimir

Vladimir Kozlov wrote:
> http://cr.openjdk.java.net/~kvn/7009359/webrev
>
> Fixed 7009359: HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
>
> StringConcat optimization replace new StringBuffer(null).toString()
> with new String("null") because new StringBuffer.append(null) is
> producing such string. Passing null to StringBuffer constructor
> is a special case which was not checked.
>
> Bailout StringConcat optimization if null is passed to
> StringBuffer constructor. Added regression test.
                                     
2010-12-29



Hardware and Software, Engineered to Work Together