JDK-7043371 : javac7 fails with NPE during compilation
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-05-10
  • Updated: 2013-11-22
  • Resolved: 2011-08-15
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 8
8Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
JDK7 compilation with javac7 fails with NPE and assertion error with several changes in one file. The log message:
compile:
    [javac] Compiling 2735 source files to /tmp/jprt/P1/B/140356.mg116726/source/build/linux-i586/jaxws/build/classes
    [javac] java.lang.NullPointerException
    [javac] 	at com.sun.tools.javac.code.Lint$AugmentVisitor.augment(Lint.java:290)
    [javac] 	at com.sun.tools.javac.code.Lint.augment(Lint.java:82)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribLazyConstantValue(Attr.java:597)
    [javac] 	at com.sun.tools.javac.code.Symbol$VarSymbol$1.call(Symbol.java:975)
    [javac] 	at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1007)
    [javac] 	at com.sun.tools.javac.comp.Attr.checkInit(Attr.java:2622)
    [javac] 	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:2280)
    [javac] 	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1677)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:449)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterAttributeValue(Annotate.java:203)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterAnnotation(Annotate.java:181)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter.enterAnnotations(MemberEnter.java:778)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter.access$300(MemberEnter.java:56)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter$5.enterAnnotation(MemberEnter.java:746)
    [javac] 	at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:109)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:101)
    [javac] 	at com.sun.tools.javac.comp.Enter.complete(Enter.java:510)
    [javac] 	at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
    [javac] 	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
    [javac] 	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:417)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:331)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:322)
    [javac] 	at com.sun.tools.javac.Main.compile(Main.java:76)
    [javac] 	at com.sun.tools.javac.Main.main(Main.java:61)
    [javac] An exception has occurred in the compiler (1.7.0-internal_bootstrap). 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.
    [javac] java.lang.AssertionError: java.lang.NullPointerException
    [javac] 	at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1010)
    [javac] 	at com.sun.tools.javac.comp.Attr.checkInit(Attr.java:2622)
    [javac] 	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:2280)
    [javac] 	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1677)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:449)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterAttributeValue(Annotate.java:203)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterAnnotation(Annotate.java:181)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter.enterAnnotations(MemberEnter.java:778)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter.access$300(MemberEnter.java:56)
    [javac] 	at com.sun.tools.javac.comp.MemberEnter$5.enterAnnotation(MemberEnter.java:746)
    [javac] 	at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:109)
    [javac] 	at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:101)
    [javac] 	at com.sun.tools.javac.comp.Enter.complete(Enter.java:510)
    [javac] 	at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
    [javac] 	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
    [javac] 	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:417)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:331)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:322)
    [javac] 	at com.sun.tools.javac.Main.compile(Main.java:76)
    [javac] 	at com.sun.tools.javac.Main.main(Main.java:61)
    [javac] Caused by: java.lang.NullPointerException
    [javac] 	at com.sun.tools.javac.code.Lint$AugmentVisitor.augment(Lint.java:290)
    [javac] 	at com.sun.tools.javac.code.Lint.augment(Lint.java:82)
    [javac] 	at com.sun.tools.javac.comp.Attr.attribLazyConstantValue(Attr.java:597)
    [javac] 	at com.sun.tools.javac.code.Symbol$VarSymbol$1.call(Symbol.java:975)
    [javac] 	at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1007)
    [javac] 	... 22 more

Will also attach failing jaxws zip file which contains the change.

Comments
EVALUATION Here's the simple test case. Note that the order of classes in this one file is significant: in particular, B must appear before A. Here is the key point: A class (B, here) uses an annotation that requires a value (Anno, here), and the value is the first seen reference to a constant value (A.a, here) that is itself annotated. ---------- Test.java ---------- @interface Anno { String value(); } class B { @Anno(value=A.a) public static final int b = 0; } class A { @Deprecated public static final String a = "a"; } ------------------------
13-06-2011

EVALUATION NPE is occurring in src/com/sun/xml/internal/bind/v2/WellKnownNamespace.java, line 45, (char 1174 in file) @Deprecated() public static final String XML_SCHEMA = XMLConstants.W3C_XML_SCHEMA_NS_URI; ^ Root cause appears to be in src/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/BindInfo.java, line 72 (char 2894 in file) @XmlRootElement(namespace=WellKnownNamespace.XML_SCHEMA,name="annotation") @XmlType(namespace=WellKnownNamespace.XML_SCHEMA,name="foobar") ^ public final class BindInfo implements Iterable<BIDeclaration> { --------- Thus is the problem revealed. javac is processing the annotations on BindInfo.java. It encounters an annotation (@XmlRootElement above) with a value (WellKnownNamespace.XML_SCHEMA) which itself has annotations on its declaration (@Deprecated) which have not yet been processed, giving rise to the NPE. Oops. The workaround that is given works because that gives javac the chance to process WellKnownNamespace.XML_SCHEMA before it is used in BindInfo.java
09-06-2011