-
Bug
-
Resolution: Fixed
-
P5
-
1.4.2, 5.0, 6
-
b114
-
generic, x86
-
generic, linux, windows_xp
-
Verified
FULL PRODUCT VERSION :
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
When you anonymously extend a class that is selectively instantiated at runtime i get a NoClassDefFound error. I have created a simple example that shows the simlpest form to recreate.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using a tenaory operator to selectively initialise a static variable
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
print Hello
ACTUAL -
Exception in thread "main" java.lang.NoClassDefFoundError: Test$1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class Test
{
private static final ArrayList<String> list = true ? null : new ArrayList<String>() { };
public static void main(String[] args)
{
System.out.println("Hello");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
don't use ternary operator to create static class, use a static intialiser.
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
When you anonymously extend a class that is selectively instantiated at runtime i get a NoClassDefFound error. I have created a simple example that shows the simlpest form to recreate.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using a tenaory operator to selectively initialise a static variable
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
print Hello
ACTUAL -
Exception in thread "main" java.lang.NoClassDefFoundError: Test$1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class Test
{
private static final ArrayList<String> list = true ? null : new ArrayList<String>() { };
public static void main(String[] args)
{
System.out.println("Hello");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
don't use ternary operator to create static class, use a static intialiser.
- duplicates
-
JDK-6228074 In light of conditional compilation, javac generates invalid "checkcast"
- Closed