Name: rmT116609 Date: 10/27/2003
FULL PRODUCT VERSION :
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The problem occurs only in the server VM!
We have a class that contains one anonymous inner class and (at least) one named inner class. The anonymous inner class definition (here a Runnable) is disabled with a "if (false)" construct. After several thousand invocations running correctly (!) a ClassLoader exception is thrown claiming it does not find the anonymous inner class definition. We found that the compiler optimized away the entire "if (false)" construct so we were surprised how the VM could know about the absent inner class, but to our surprise we found a reference to it in a weird constructor of the named inner class which has a reference to the anonymous one as second argument, not written by us!
Apparently (from the stacktrace), this second constructor is tried to be used only after hotspot optimized the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the appended short example that reproduces the problem reliably.
Simply compile and then start with "java -server" option.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions in execution of the demo
ACTUAL -
After a number of dot-lines indicating correct behaviour for thousands of calls the same stacktrace always appears.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ClassNotFoundException: InnerClassServerVMBug$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at com.orbotech.flash.jochenr.InnerClassServerVMBug$Data.<init>(InnerClassServerVMBug.java:40)
at com.orbotech.flash.jochenr.InnerClassServerVMBug.internalCalculate(InnerClassServerVMBug.java:29)
at com.orbotech.flash.jochenr.InnerClassServerVMBug.calculate(InnerClassServerVMBug.java:25)
at com.orbotech.flash.jochenr.InnerClassServerVMBug.main(InnerClassServerVMBug.java:58)
Exception in thread "main" Process terminated with exit code 1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class InnerClassServerVMBug {
private int _value;
public InnerClassServerVMBug() {
_value = 0;
}
public void calculate() {
if (false) {
new Runnable() {
public void run() {
internalCalculate();
}
}.run();
} else
internalCalculate();
}
private void internalCalculate() {
setValue(new Data(0).getData());
}
private void setValue(int result) {
_value = result;
}
public int getValue() {
return _value;
}
private class Data {
int _data;
private Data(int data) {
_data = data;
}
public int getData() {
return _data;
}
}
public static void main(String[] args) throws Exception {
final InnerClassServerVMBug p = new InnerClassServerVMBug();
long sum = 0;
int idx = 0;
while (sum < 10000000L) {
p.calculate();
sum += p.getValue();
System.out.print(".");
if (++idx >= 100) {
System.out.println();
idx = 0;
}
System.out.flush();
}
System.out.println("sum = " + sum);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Commenting out the anonymous inner class code instead of using "if (false){}" block
(Incident Review ID: 217483)
======================================================================
- relates to
-
JDK-6624474 Server compiler generates unexpected LinkageError
-
- Resolved
-
-
JDK-4954586 inner class file is not generated
-
- Closed
-