JDK-6678999 : Stacktrace missing after null string comparisons
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2008-03-24
  • Updated: 2011-02-16
  • Resolved: 2008-04-07
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)

and

java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) Server VM (build 1.5.0_13-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Ubuntu Gutsy 32-bits (reproduced on a RedHat Enterprise Edition)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested on a Core 2 Duo (model 6400) 2.13Ghz with 2Gb RAM

A DESCRIPTION OF THE PROBLEM :
After comparing a string to null and catching the exception and repeating the operation, JVM starts throwing "stackless" NullPointerException (it occurs after 9000 loops but this is variable)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Stacktrace should be always be printed.
ACTUAL -
After around 9000 times the stacktrace is ommited.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Console output snippet:

java.lang.NullPointerException
	at java.lang.String.startsWith(String.java:1422)
	at java.lang.String.startsWith(String.java:1451)
	at Bug.main(Bug.java:8)
java.lang.NullPointerException
	at java.lang.String.startsWith(String.java:1422)
	at java.lang.String.startsWith(String.java:1451)
	at Bug.main(Bug.java:8)
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
 public static void main(String[] args) {
        
        for (int i = 0; i < Integer.MAX_VALUE/100000; i++) {
            
            try {
                System.out.println(i);
                "ABC".startsWith(null);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Couldn't reproduce after adding a System.gc() before comparing the string.

Comments
WORK AROUND Use the -XX:-OmitStackTraceInFastThrow option.
07-04-2008

EVALUATION When the server compiler compiles a method, the stack trace in an exception thrown by that method may be omitted for performance purposes. In this case, the stacktrace disappears when the String.startsWith method is compiled. If the user always wants stack traces, use the -XX:-OmitStackTraceInFastThrow option to the VM.
07-04-2008

EVALUATION Similar to 4292742 which was fixed in 1.3.1_14. Routing to the owners of that issue for their evaluation.
07-04-2008