FULL PRODUCT VERSION :
java version " 1.7.0_25 "
Java(TM) SE Runtime Environment (build 1.7.0_25_b16)
Java Hotspot(TM) 64-bit Server VM (build 23.25-b01, mixed mode)
FULL OS VERSION :
Windows 7 64-bit
EXTRA RELEVANT SYSTEM CONFIGURATION :
No additional configuration needed
A DESCRIPTION OF THE PROBLEM :
The attached sample program calls a method 10'000 times without changing any border conditions. As soon as the method gets compiled, the result of that method returns null instead of a instance.
Please note that the attached sample was stripped down a lot and multiple coding standards were violated to make the sample code as small as possible.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) compile the sample java program
2) run it with the java interpreter -> run through
3) run it with the jit enabled -> returned method value is null and it throws an exception
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect that the program never throws an excpetion
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error messages
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;
public class TestJITError {
public static class NamedObject {
public int id;
public String name;
public NamedObject(int id, String name) {
this.id = id;
this.name = name;
}
}
public static class NamedObjectList {
public List<NamedObject> namedObjectList = new ArrayList<NamedObject>();
public NamedObject getBest(int id) {
NamedObject bestObject = null;
for (NamedObject o : namedObjectList) {
bestObject = id==o.id ? getBetter(bestObject, o) : bestObject;
}
return bestObject != null ? bestObject : null;
}
private static NamedObject getBetter(NamedObject p1, NamedObject p2) {
return p1 == null ? p2 : (p2 == null) ? p1 : p2.name.compareTo(p1.name)>=0 ? p2 : p1;
}
}
public static void main(String[] args) {
// setup
NamedObjectList b = new NamedObjectList();
for (int i = 0; i < 10000; i++) {
b.namedObjectList.add(new NamedObject(1, " 2012-12-31 " ));
}
b.namedObjectList.add(new NamedObject(2, " 2013-12-31 " ));
// execution
for (int i = 0; i < 100000; i++) {
NamedObject x = b.getBest(2);
// test
if (x == null) {
throw new RuntimeException( " x should never be null here!! (i= " + i + " ) " );
}
}
System.out.println( " finished " );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Refactoring of the java code will make it behave correctly.