JDK-5094120 : Javac crashes with NPE
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-30
  • Updated: 2004-09-15
  • Resolved: 2004-09-15
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 08/30/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b60)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b60, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
Javac's type inference algorithm fails with NPE if one refers to a type variable that is still "undeclared".
Additionally, the referring type variable itself must have multiple bounds?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the sample provided.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compile should succeed no matter how the parameters of Bug#defError are organised.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at com.sun.tools.javac.code.Types.capture(Types.java:2671)
	at com.sun.tools.javac.code.Types$IsSubTypeFcn.isSubType(Types.java:338)
	at com.sun.tools.javac.code.Types$IsSubTypeFcn.visitType(Types.java:384)
	at com.sun.tools.javac.code.Type$Visitor.visitTypeVar(Type.java:958)
	at com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:790)
	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.Check.checkExtends(Check.java:412)
	at com.sun.tools.javac.comp.Check.access$100(Check.java:37)
	at com.sun.tools.javac.comp.Check$Validator.visitTypeApply(Check.java:781)
	at com.sun.tools.javac.tree.Tree$TypeApply.accept(Tree.java:1064)
	at com.sun.tools.javac.comp.Check.validate(Check.java:716)
	at com.sun.tools.javac.comp.Check.validate(Check.java:726)
	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2382)
	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.comp.Attr.visitTypeParameter(Attr.java:2268)
	at com.sun.tools.javac.tree.Tree$TypeParameter.accept(Tree.java:1080)
	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.MemberEnter.signature(MemberEnter.java:341)
	at com.sun.tools.javac.comp.MemberEnter.visitMethodDef(MemberEnter.java:554)
	at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
	at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:383)
	at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:395)
	at com.sun.tools.javac.comp.MemberEnter.finishClass(MemberEnter.java:405)
	at com.sun.tools.javac.comp.MemberEnter.finish(MemberEnter.java:952)
	at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:919)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:355)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:614)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:448)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:426)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:382)
	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 ----------
public class Bug {

	public static void main(String[] args){
		DummyParameterTakerImpl dpti = new DummyParameterTakerImpl();
		
		defOk(dpti);
		defError(dpti);
	}

	/**
	 * A's decl occurs _before_ it is "used"
	 */
	static <A extends Parameter, B extends Dummy & ParameterTaker<A>> void defOk(B b){
	}
	
	/**
	 * A's decl occurs _after_ it is "used" - Results in a NPE
	 */
	static <B extends ParameterTaker<A> & Dummy, A extends Parameter> void defError(B b){
	}

	interface Dummy {} // Needed for multiple bounds

	interface ParameterTaker <P extends Parameter> {}
	
	interface Parameter {}

	static class DummyParameterTakerImpl implements ParameterTaker<Parameter>, Dummy {}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Change the order of the variables "A" and "B" (see Bug#defOk).
(Incident Review ID: 301328) 
======================================================================

Comments
EVALUATION Yes, this is a bug. ###@###.### 2004-08-30
30-08-2004