我正在开发 Java 注释处理器,遇到 NullPointerException 并显示以下错误消息:
An exception has occurred in the compiler (21.0.3). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol$MethodSymbol.flags()" because "rc.accessor" is null
at jdk.compiler/com.sun.tools.javac.comp.Lower.lambda$generateMandatedAccessors$5(Lower.java:2390)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at jdk.compiler/com.sun.tools.javac.comp.Lower.generateMandatedAccessors(Lower.java:2397)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitRecordDef(Lower.java:2594)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2289)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:814)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2181)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2200)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:4293)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1654)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1468)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:976)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:214)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1228)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:215)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:903)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:280)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:203)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
运行以下类后会发生此错误,该类负责从我的 JAR 中的特定包加载和处理 Java 源文件:
要点:
我目前的做法:
问题:
您看到的错误表明在编译 Java 项目期间出现 NullPointerException。这个问题似乎与Java编译器(javac)有关,并且在调用方法com.sun.tools.javac.code.Symbol$MethodSymbol.flags()时发生。
您可以按照以下步骤尝试解决此问题:
检查您的代码:确保您的代码中没有明显的错误 这可能会导致这个问题。请特别注意 发生错误时正在编译的类和方法。
更新您的 JDK:确保您使用的是最新版本的 JDK。 有时这些问题会在较新版本的编译器中得到解决。
清理并重新编译您的项目:有时编译的文件可能位于 不一致的状态。尝试清理并重新编译您的项目。如果 你正在使用 Maven,你可以运行:
mvn clean install
验证依赖项:确保项目中的所有依赖项都是 正确配置且是最新的。有时会发生冲突的库 可能会在编译过程中引起问题。
检查记录的使用:错误提到visitRecordDef, 推测这可能与Java中记录的使用有关。确保 记录被正确定义和使用。
检查 Java 错误跟踪器:查阅 Java 错误数据库以查看是否 这个问题已经被报告过,如果有任何解决方案或 可用更新。