JDK-7074442 : Cast with unbounded wildcards with fbounds causes infinite loop in javac
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u26
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-08-03
  • Updated: 2013-08-01
  • Resolved: 2013-08-01
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
javac 1.6.0_26

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The program copied below should compile, but causes an infinite recursion instead.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the source code given below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile withouth problem.
ACTUAL -
It produces a stack overflow shown below

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$1.visitWildcardType(Types.java:98)
        at com.sun.tools.javac.code.Type$WildcardType.accept(Type.java:416)
        at com.sun.tools.javac.code.Types$MapVisitor.visit(Types.java:3270)
        at com.sun.tools.javac.code.Types.upperBound(Types.java:95)
        at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2990)
        at com.sun.tools.javac.code.Types.adapt(Types.java:3020)
        at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2981)
        at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2990)
        at com.sun.tools.javac.code.Types.adapt(Types.java:3020)
[...]


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class StackOverflow implements AInterface<AClass<?>> {
	@Override
	public void doA(final AInterface<AClass<?>> vm) {
		final StackOverflow cast = (StackOverflow) vm;
	}
}

class AClass<T extends Comparable<T>> {}

interface AInterface<V> {
	void doA(AInterface<V> vm);
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
It is working in Java7.

If possible, you can change the code to use a specific generic type, that way it will also compile with Java6:

class StackOverflow<S extends Comparable<S>> implements AInterface<AClass<S>> {
	@Override
	public void doA(final AInterface<AClass<S>> vm) {
		final StackOverflow cast = (StackOverflow) vm;
	}
}

class AClass<T extends Comparable<T>> {}

interface AInterface<V> {
	void doA(AInterface<V> vm);
}

Comments
Duplicate of 6651719.
01-08-2013

Not reproducible with both jdk7 and jdk8. Closing as duplicate.
01-08-2013

Alex, can you see if this bug reproduces in the latest jdk 7 and jdk 8 and if not, please closed it as a dup of the bug mentioned by Maurizio.
26-04-2013

EVALUATION This looks like a duplicate of 6651719. The stack trace is different but the underlying cause is the same (wildcards as bounds of other wildcards because of erroneous capture conversion). This bug is not reproducible since jdk7 b33 (which introduced a fix for 6651719).
03-08-2011