JDK-7006848 : NullPointerException in javac
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2010-12-14
  • Updated: 2012-03-20
  • Resolved: 2011-01-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
C:\java\jdk1.7.0\bin>java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b119)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b03, mixed mode

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

A DESCRIPTION OF THE PROBLEM :
javac fails with NullPointerException when compiling simple file




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run
> javac Bug.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it should compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.7.0-ea). 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.NullPointerException
        at com.sun.tools.javac.code.Types.closure(Types.java:2485)
        at com.sun.tools.javac.code.Types.glb(Types.java:2780)
        at com.sun.tools.javac.code.Types.glb(Types.java:2767)
        at com.sun.tools.javac.comp.Infer.maximizeInst(Infer.java:213)
        at com.sun.tools.javac.comp.Infer.instantiateExpr(Infer.java:314)
        at com.sun.tools.javac.comp.Check.instantiatePoly(Check.java:439)
        at com.sun.tools.javac.comp.Check.checkType(Check.java:407)
        at com.sun.tools.javac.comp.Attr.check(Attr.java:207)
        at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1480)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1324)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:433)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:420)
        at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:451)
        at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1300)
        at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1243)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:433)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:420)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:482)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:498)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:860)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:784)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:433)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:420)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:482)
        at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:781)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:671)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:433)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:420)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:482)
        at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:3129)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:3052)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2988)
        at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1146)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:836)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:795)
        at com.sun.tools.javac.main.Main.compile(Main.java:418)
        at com.sun.tools.javac.main.Main.compile(Main.java:336)
        at com.sun.tools.javac.main.Main.compile(Main.java:327)
        at com.sun.tools.javac.Main.compile(Main.java:82)
        at com.sun.tools.javac.Main.main(Main.java:67)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class Bug {
  boolean a() {return b();}
  <T> T b() {return null;}
}

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

CUSTOMER SUBMITTED WORKAROUND :
cast b() to Boolean.

class Bug {
  boolean a() {return (Boolean) b();}
  <T> T b() {return null;}
}

Comments
EVALUATION Fixed in b121 by the fix for 6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
04-01-2011