JDK-7009359 : HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: x86
  • Submitted: 2010-12-28
  • Updated: 2013-02-11
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u25Fixed 7Fixed hs20Fixed
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
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.
29-12-2010

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