United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6273455 : crash: java.lang.StackOverflowError at com.sun.tools.javac.code.Types

Details
Type:
Bug
Submit Date:
2005-05-20
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2006-01-07
Component:
tools
OS:
generic,windows_xp
Sub-Component:
javac
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description
This program doesn't compile and causes a stack overflow:

import java.util.*;

class Test<T extends Comparable<? super T>> {

    abstract class Group<E extends Comparable<? super E>> 
	extends ArrayList<E> 
	implements Comparable<Group<? extends E>> {}

    abstract class Sequence<E extends Comparable<? super E>>
	extends TreeSet<E>
	implements Comparable<Sequence<? extends E>> {}

    public void containsCombination(SortedSet<Group<T>> groups,
				    SortedSet<Sequence<T>> sequences) {
	foo(groups, sequences);
    }

    <C extends Collection<T>> void foo(SortedSet<? extends C> setToCheck,
				       SortedSet<? extends C> validSet) {}

}

###@###.### 2005-05-20 01:26:32 GMT
Stack overflow in 5.0u6:

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
        at com.sun.tools.javac.code.Type.accept(Type.java:80)
        at com.sun.tools.javac.code.Types.lowerBound(Types.java:112)
        at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitClassType(Types.java:410)
        at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482)
        at com.sun.tools.javac.code.Types$IsSubTypeFcn.isSubType(Types.java:347)

                                    

Comments
WORK AROUND

Use explicit type argument:

this.<Collection<T>>foo(groups, sequences);

instead of:

	foo(groups, sequences);

###@###.### 2005-05-20 01:26:32 GMT
                                     
2005-05-20
SUGGESTED FIX

Ensure that substitution doesn't create "infinite" ? extends ? extends ... T wildcards.

Index: src/share/classes/com/sun/tools/javac/code/Types.java
============================================================
@@ -2126,9 +2126,12 @@
 		t = subst(t);
 	    if (t == that.type)
 		result = that;
-	    else
+	    else {
+		if (t.isExtendsBound() && that.isExtendsBound())
+		    t = upperBound(t);
 		result = new WildcardType(t, that.kind, syms.boundClass, that.bound);
         }
+        }
 
 	public void visitArrayType(ArrayType t) {
             Type elemtype = subst(t.elemtype);

###@###.### 2005-05-20 01:26:32 GMT
                                     
2005-05-20
EVALUATION

This is a bug in inference causing creation of "infinite" wildcards.

###@###.### 2005-05-20 01:26:32 GMT
                                     
2005-05-20
SUGGESTED FIX

http://sa.sfbay.sun.com/projects/langtools_data/mustang/6273455/
                                     
2006-01-26



Hardware and Software, Engineered to Work Together