JDK-7104612 : Deprecated strings in annotations throw nullpointer exception during compilation
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-10-25
  • Updated: 2012-03-20
  • Resolved: 2011-10-25
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)

FULL OS VERSION :
Linux 10.04

A DESCRIPTION OF THE PROBLEM :
When you create an annotation with a string value inside and assign it to e.g. a method, and you use as value a deprecated static final string, the compiler throws a nullpointer-exception. Note that the deprecated string MUST be in another class. When the deprecated string is defined where the annotation is applied, it will compile.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Class 1:

public class LocalNames {
    @Deprecated
    final public static String WHATEVER = "whatever";
}

Class 2:
public @interface Test {
    public String value() default "";
}

Class 3:
public class JavaApplication14 {
    @Test(LocalNames.WHATEVER)
    public static void main(String[] args) {
        // TODO code application logic here
    }
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
Should compile
ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.7.0_01). 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: java.lang.NullPointerException
	at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1005)
	at com.sun.tools.javac.comp.Attr.checkInit(Attr.java:2627)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:2285)
	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1677)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
	at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:449)
	at com.sun.tools.javac.comp.Annotate.enterAttributeValue(Annotate.java:203)
	at com.sun.tools.javac.comp.Annotate.enterAnnotation(Annotate.java:181)
	at com.sun.tools.javac.comp.MemberEnter.enterAnnotations(MemberEnter.java:778)
	at com.sun.tools.javac.comp.MemberEnter.access$300(MemberEnter.java:56)
	at com.sun.tools.javac.comp.MemberEnter$5.enterAnnotation(MemberEnter.java:746)
	at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:109)
	at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:101)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:510)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
	at com.sun.tools.javac.main.Main.compile(Main.java:417)
	at com.sun.tools.javac.main.Main.compile(Main.java:331)
	at com.sun.tools.javac.main.Main.compile(Main.java:322)
	at com.sun.tools.javac.Main.compile(Main.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
	at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1134)
	at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
	at org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:144)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:390)
	at org.apache.tools.ant.Target.performTasks(Target.java:411)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
	at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
	at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
	at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
Caused by: java.lang.NullPointerException
	at com.sun.tools.javac.code.Lint$AugmentVisitor.augment(Lint.java:290)
	at com.sun.tools.javac.code.Lint.augment(Lint.java:82)
	at com.sun.tools.javac.comp.Attr.attribLazyConstantValue(Attr.java:597)
	at com.sun.tools.javac.code.Symbol$VarSymbol$1.call(Symbol.java:971)
	at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1003)
	... 58 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Create one project and following classes.

Class 1:
public class LocalNames {
    @Deprecated
    final public static String WHATEVER = "whatever";
}

Class 2:
public @interface Test {
    public String value() default "";
}

Class 3:
public class JavaApplication14 {
    @Test(LocalNames.WHATEVER)
    public static void main(String[] args) {
        // TODO code application logic here
    }
}
---------- END SOURCE ----------