Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7009359

HS with -XX:+AggressiveOpts optimize new StringBuffer(null) so it does not throw NPE as expected

XMLWordPrintable

    • b06
    • x86
    • generic
    • Verified

        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

              kvn Vladimir Kozlov
              lmesnik Leonid Mesnik
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: