Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6215213
Votes 1
Synopsis crash: java.lang.AssertionError at com.sun.tools.javac.code.Types.containedBy(Types.java:792)
Category java:compiler
Reported Against
Release Fixed mustang(b67)
State 10-Fix Delivered, Verified, bug
Priority: 2-High
Related Bugs 5080917
Submit Date 07-JAN-2005
Description
FULL PRODUCT VERSION :
J2SE(TM) Development Kit 5.0 Update 1 (jdk 1.5.0.01)

ADDITIONAL OS VERSION INFORMATION :
Suse 9.2 professionnal (kernel 2.6.8)

A DESCRIPTION OF THE PROBLEM :
import java.util.*;

public class Generic {

	public <K> TreeMap<K,K> essai(K type) {
		TreeMap<K,K> treeMap = new TreeMap<K,K>();
		return treeMap;
	}

	public static void main(String args[]) {
		Generic generic = new Generic();

		//et ci-dessous c'est le drame
		TreeMap<?,?> treeMap = generic.essai(null);

	}
}

------------------------------------------------------------------------

Try to compile the program above

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.*;

public class Generic {

	public <K> TreeMap<K,K> essai(K type) {
		TreeMap<K,K> treeMap = new TreeMap<K,K>();
		return treeMap;
	}

	public static void main(String args[]) {
		Generic generic = new Generic();

		//et ci-dessous c'est le drame
		TreeMap<?,?> treeMap = generic.essai(null);

	}
}

------------------------------------------------------------------------

Try to compile the program above

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I don't know, but the compiler said me it crashed and send you this report of bug
ACTUAL -
Compiler crashes

ERROR MESSAGES/STACK TRACES THAT OCCUR :
hibounds=java.lang.Object
An exception has occurred in the compiler (1.5.0-rc). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.AssertionError
        at com.sun.tools.javac.code.Types.containedBy(Types.java:792)
        at com.sun.tools.javac.code.Types$ContainsTypeFcn.visitArgumentType(Types.java:871)
        at com.sun.tools.javac.code.Type$ArgumentType.accept(Type.java:358)
        at com.sun.tools.javac.code.Types$ContainsTypeFcn.containsType(Types.java:851)
        at com.sun.tools.javac.code.Types.containsType(Types.java:841)
        at com.sun.tools.javac.code.Types.containsType(Types.java:811)
        at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitClassType(Types.java:421)
        at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:473)
        at com.sun.tools.javac.code.Types$IsSubTypeFcn.isSubType(Types.java:344)
        at com.sun.tools.javac.code.Types.isSubType(Types.java:327)
        at com.sun.tools.javac.comp.Infer.instantiateExpr(Infer.java:237)
        at com.sun.tools.javac.comp.Check.instantiatePoly(Check.java:354)
        at com.sun.tools.javac.comp.Check.checkType(Check.java:322)
        at com.sun.tools.javac.comp.Attr.check(Attr.java:140)
        at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1110)
        at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:819)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
        at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:271)
        at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:531)
        at com.sun.tools.javac.tree.Tree$VarDef.accept(Tree.java:511)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:291)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:307)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:561)
        at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:540)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:291)
        at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:494)
        at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:291)
        at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2424)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2357)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2306)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:410)
        at com.sun.tools.javac.main.Main.compile(Main.java:592)
        at com.sun.tools.javac.main.Main.compile(Main.java:544)
        at com.sun.tools.javac.Main.compile(Main.java:58)
        at com.sun.tools.javac.Main.main(Main.java:48)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;

public class Generic {

	public <K> TreeMap<K,K> essai(K type) {
		TreeMap<K,K> treeMap = new TreeMap<K,K>();
		return treeMap;
	}

	public static void main(String args[]) {
		Generic generic = new Generic();

		//et ci-dessous c'est le drame
		TreeMap<?,?> treeMap = generic.essai(null);

	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
import java.util.*;

public class Generic {

	public <K> TreeMap<K,K> essai(K type) {
		TreeMap<K,K> treeMap = new TreeMap<K,K>();
		return treeMap;
	}

	public static void main(String args[]) {
		Generic generic = new Generic();

		//use whatever but not wildcard type even if it doesn't mean the same
		TreeMap<Object,Object> treeMap = generic.essai(null);

	}
}
  xxxxx@xxxxx   2005-1-07 18:48:49 GMT
Work Around
Insert a cast:
TreeMap<?,?> treeMap = (TreeMap<Object,Object>)generic.essai(null);

  xxxxx@xxxxx   2005-1-07 19:48:40 GMT
Preferably, add an explicit type argument:

	TreeMap<?,?> treeMap = generic.<Object>essai(null);
Evaluation
This is most likely a bug related to how underconstrained type variables
are determined.
  xxxxx@xxxxx   2005-1-07 19:48:40 GMT
Fixing this requires a glb calculation of the multiple constraints on K
which fixes 5080917.
Posted Date : 2005-12-04 18:12:50.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang