-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
7u67, 8u25
-
x86
-
windows_8
FULL PRODUCT VERSION :
C:\Users\Lukas\IdeaProjects\untitled\src>javac -version
javac 1.8.0_25
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
There are some caveats with generic types. Some questions are simply undecidable. If I compile "undecidable" programs, javac will crash with a StackOverflowError.
This bug is also present in Eclipse, where I have filed a separate report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=449554
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
There are some caveats with generic types. Some questions are simply undecidable, such as whether the following programme should compile:
------------------------------------------------------
interface Type<T> {}
class C implements Type<Type<? super C>> {}
class D<P> implements Type<Type<? super D<D<P>>>> {}
class Test {
Type<? super C> c = new C();
Type<? super D<Byte>> d = new D<Byte>();
}
------------------------------------------------------
Compiling the above program crashes javac, because the type assignments are undecidable. The reasons why this is undecidable are explained on page 3 of this paper by Ross Tate:
http://www.cs.cornell.edu/~ross/publications/tamewild/tamewild-tate-pldi11.pdf
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd expect this to be handled, and a generic error for this class to be reported.
ACTUAL -
C:\Users\Lukas\IdeaProjects\untitled\src>javac Test.java
Test.java:7: error: incompatible types: C cannot be converted to Type<? super C>
Type<? super C> c = new C();
^
The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3726)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3731)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3731)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
------------------------------------------------------
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
interface Type<T> {}
class C implements Type<Type<? super C>> {}
class D<P> implements Type<Type<? super D<D<P>>>> {}
class Test {
Type<? super C> c = new C();
Type<? super D<Byte>> d = new D<Byte>();
}
---------- END SOURCE ----------
C:\Users\Lukas\IdeaProjects\untitled\src>javac -version
javac 1.8.0_25
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
There are some caveats with generic types. Some questions are simply undecidable. If I compile "undecidable" programs, javac will crash with a StackOverflowError.
This bug is also present in Eclipse, where I have filed a separate report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=449554
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
There are some caveats with generic types. Some questions are simply undecidable, such as whether the following programme should compile:
------------------------------------------------------
interface Type<T> {}
class C implements Type<Type<? super C>> {}
class D<P> implements Type<Type<? super D<D<P>>>> {}
class Test {
Type<? super C> c = new C();
Type<? super D<Byte>> d = new D<Byte>();
}
------------------------------------------------------
Compiling the above program crashes javac, because the type assignments are undecidable. The reasons why this is undecidable are explained on page 3 of this paper by Ross Tate:
http://www.cs.cornell.edu/~ross/publications/tamewild/tamewild-tate-pldi11.pdf
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd expect this to be handled, and a generic error for this class to be reported.
ACTUAL -
C:\Users\Lukas\IdeaProjects\untitled\src>javac Test.java
Test.java:7: error: incompatible types: C cannot be converted to Type<? super C>
Type<? super C> c = new C();
^
The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3726)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3731)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3731)
at com.sun.tools.javac.code.Types$26.visitClassType(Types.java:3718)
at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4532)
------------------------------------------------------
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
interface Type<T> {}
class C implements Type<Type<? super C>> {}
class D<P> implements Type<Type<? super D<D<P>>>> {}
class Test {
Type<? super C> c = new C();
Type<? super D<Byte>> d = new D<Byte>();
}
---------- END SOURCE ----------
- duplicates
-
JDK-6558545 Undecidable type system leads to stack overflow
-
- Open
-