Duplicate :
|
FULL PRODUCT VERSION : java version "1.5.0_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05) Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Windows XP sp2 Linux 2.6.11 (Gentoo) A DESCRIPTION OF THE PROBLEM : While investigating the behavior of some bizarre uses of generics (for some graduate research), I stumbled across the following code that will cause a compiler crash. It seems similar to bugs: 4856983, 4991190 , 5097944 , 5094120, but I'm not sure it's directly related. (Though admittedly, I have not yet actually found a pragmatic use for the example.) STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Attempt to compile the example code. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Successful compilation -or- compiler error message ACTUAL - Compiler crashes with: The system is out of resources. Consult the following stack trace for details. java.lang.StackOverflowError ERROR MESSAGES/STACK TRACES THAT OCCUR : The system is out of resources. Consult the following stack trace for details. java.lang.StackOverflowError at com.sun.tools.javac.code.Types.supertype(Types.java:1715) at com.sun.tools.javac.code.Types$AsSuperFcn.visitClassType(Types.java:1400) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482) at com.sun.tools.javac.code.Types$AsSuperFcn.asSuper(Types.java:1385) at com.sun.tools.javac.code.Types$AsSuperFcn.visitClassType(Types.java:1402) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482) at com.sun.tools.javac.code.Types$AsSuperFcn.asSuper(Types.java:1385) at com.sun.tools.javac.code.Types.asSuper(Types.java:1375) at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitClassType(Types.java:423) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482) at com.sun.tools.javac.code.Types$IsSubTypeFcn.isSubType(Types.java:347) at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitArgumentType(Types.java:402) at com.sun.tools.javac.code.Type$ArgumentType.accept(Type.java:367) at com.sun.tools.javac.code.Types$IsSubTypeFcn.isSubType(Types.java:347) at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitArgumentType(Types.java:402) [...] REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class CompilerCrash { //dummy method1 public static <T> T crash(T t1, T t2) { return t1; } //dummy method2 public static <T> T noCrash(T t1) { return t1; } public static void main(String ...args) { Generic<?> g1 = new Generic<String>("crash"); Generic<?> g2 = new Generic<String>("me"); noCrash(g2); // no crash crash(g1,g2); // crash!!! } } //dummy interface interface myInterface<T> { } // Note: crashes with "myInterface<Generic<? super T>>", as well. class Generic<T> implements myInterface<Generic<? extends T>> { public Generic(T s) { } } ---------- END SOURCE ---------- ###@###.### 2005-07-13 19:29:41 GMT