1

环境:

Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_01
OS name: "linux" version: "3.2.0-33-generic" arch: "amd64" Family: "unix"

文件:

1.TestAnnotation.java

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface TestAnnotation {
    public String[] lists();
}

2.Test.java

public class Test {
    //pure string instead of Test1.TEST1 has no problem
    @TestAnnotation(lists = {Test1.TEST1})  
    public static final String TEST = "test";

}

3.Test1.java

public class Test1 {
    //pure string instead of Test.TEST has no problem
    @TestAnnotation(lists = {Test.TEST})
    public static final String TEST1 = "test1";
}

问题:

当你通过运行来编译文件时mvn clean package,你会得到如下异常:

[INFO] Compilation failure
Failure executing javac, but could not parse the error:
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.enterAttributeValue(Annotate.java:243)
    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:94)
    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.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:420)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:141)
    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:493)
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    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.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
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)
    ... 49 more

任何解决方法?这是在更高版本的jdk中修复的吗?

4

0 回答 0