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.