JDK-6332204 : com.sun.tools.javac.code.Types.lub() throws NPE
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0,6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-10-04
  • Updated: 2011-02-16
  • Resolved: 2005-11-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b54)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b54, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
lub() thows a NullPointerException in case of a mix of
varags/unboxing and generics.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the example

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The two methods min are ambiguous.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.6.0-ea). Please file a bug at the J
ava Developer Connection (http://java.sun.com/webapps/bugreport)  after checking
 the Bug Parade for duplicates. Include your program and the following diagnosti
c in your report.  Thank you.
java.lang.NullPointerException
        at com.sun.tools.javac.code.Types.lub(Types.java:2569)
        at com.sun.tools.javac.code.Types.lub(Types.java:2583)
        at com.sun.tools.javac.comp.Infer.minimizeInst(Infer.java:187)
        at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:328)
        at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:307)
        at com.sun.tools.javac.comp.Resolve.instantiate(Resolve.java:332)
        at com.sun.tools.javac.comp.Resolve.mostSpecific(Resolve.java:570)
        at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:543)
        at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:720)
        at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:686)
        at com.sun.tools.javac.comp.Resolve.findFun(Resolve.java:766)
        at com.sun.tools.javac.comp.Resolve.resolveMethod(Resolve.java:1157)
        at com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:1620)
        at com.sun.tools.javac.tree.Tree$Ident.accept(Tree.java:1251)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:292)
        at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1149)
        at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:992)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:336)
        at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1141)
        at com.sun.tools.javac.tree.Tree$Apply.accept(Tree.java:992)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:299)
        at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:925)
        at com.sun.tools.javac.tree.Tree$Exec.accept(Tree.java:888)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:312)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:328)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:626)
        at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:630)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:312)
        at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:537)
        at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:545)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:277)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:312)
        at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2525)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2457)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2393)
        at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:636
)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:549)
        at com.sun.tools.javac.main.Main.compile(Main.java:680)
        at com.sun.tools.javac.main.Main.compile(Main.java:611)
        at com.sun.tools.javac.main.Main.compile(Main.java:607)
        at com.sun.tools.javac.Main.compile(Main.java:70)
        at com.sun.tools.javac.Main.main(Main.java:55)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Min {
    public static int min(int a, int ... ints){

  int minTmp=a;
  for(int num:ints){
      if(num < minTmp)
    minTmp = num;
  }
  return minTmp;
  }
    
    public static <T extends Comparable<T>> T min(T a, T ... ints){
  T minTmp=a;
  for(T num:ints){
      if(num.compareTo(minTmp) < 0)
    minTmp = num;
  }
  return minTmp;
    }
    
    public static void main(String[] args){
  System.out.println(min(Integer.valueOf(1), Integer.valueOf(2)));
    }
}
---------- END SOURCE ----------

Comments
SUGGESTED FIX Index: src/share/classes/com/sun/tools/javac/code/Types.java ============================================================ @@ -2308,6 +2319,8 @@ int boundkind = 0; for (List<Type> l = ts; l.nonEmpty(); l = l.tail) { if (l.head.tag == CLASS) boundkind |= CLASS_BOUND; + else if (l.head.isPrimitive()) /* auto-boxing */ + boundkind |= CLASS_BOUND; else if (l.head.tag == ARRAY) boundkind |= ARRAY_BOUND; else if (l.head.tag == TYPEVAR) { Type b = l.head.getUpperBound();
28-10-2005

EVALUATION Here is an example derived from a SDN comment: import java.util.*; class Bug { void bug(int[][] data, Comparator c) { Arrays.binarySearch(data, 1, c); } }
28-10-2005

EVALUATION Based on the SDN comment, I would say that it not completely unlikely that users will run into this problem. Especially when experimenting with the new language features and arrays. We should thus try to address this before Mustang RC and consider a packport to Tiger.
28-10-2005

WORK AROUND Work around for SDN comment: don't use auto-boxing: Arrays.binarySearch(data, Integer.valueOf(1) ...
28-10-2005

WORK AROUND Change the declaration of one of the second min methods: public static int min(int a, int [] ints) public static <T extends Comparable<T>> T min(T a, T[] ints) And create the array explicitly: System.out.println(min(Integer.valueOf(1), new Integer[]{Integer.valueOf(2)}));
07-10-2005

EVALUATION javac should not crash and should accept this program.
07-10-2005