3

I can't build my code with the checker framework anymore. When I comment out the checker framework annotation processor, my code compiles fine, so the problem isn't with my code. With the framework, I get this error message:

[ERROR] InvocationTargetException when invoking constructor for class 
org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory; Underlying cause: 
java.lang.NoSuchFieldError: RELEASE
  Exception: java.lang.reflect.InvocationTargetException; Stack trace: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:275)
  org.checkerframework.common.basetype.BaseTypeVisitor.createTypeFactory(BaseTypeVisitor.java:261)
  ...

(Full stack trace is at the bottom.)

This stack trace doesn't reference anything in my code. It appears to be a bug in the nullness checker.

I'm using the current version of maven (3.6.3) and the maven compiler plug-in (3.8.1). I'm using JDK 1.8.

To see the pom.xml file and the code, check out the repository at https://github.com/SwingGuy1024/CheckerNoSuchFieldErrorBug Here's a link to the pom file: https://github.com/SwingGuy1024/CheckerNoSuchFieldErrorBug/blob/master/pom.xml

To reproduce the bug using Maven, download the repository and type mvn clean install

Here's the full stack trace:

[ERROR] InvocationTargetException when invoking constructor for class org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory; Underlying cause: java.lang.NoSuchFieldError: RELEASE
  Exception: java.lang.reflect.InvocationTargetException; Stack trace: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:275)
  org.checkerframework.common.basetype.BaseTypeVisitor.createTypeFactory(BaseTypeVisitor.java:261)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:220)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:209)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:224)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:85)
  org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:904)
  org.checkerframework.common.basetype.BaseTypeChecker.initChecker(BaseTypeChecker.java:100)
  org.checkerframework.common.basetype.BaseTypeChecker.initChecker(BaseTypeChecker.java:91)
  org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:860)
  org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:157)
  com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
  com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1342)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1296)
  com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
  com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
  com.sun.tools.javac.main.Main.compile(Main.java:523)
  com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
  com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
  org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
  org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
  org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1134)
  org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:187)
  org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
  org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
  org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
  org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
  org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
  org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:498)
  org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
  org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
  org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
  org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
  org.codehaus.classworlds.Launcher.main(Launcher.java:47)
  Underlying Exception: java.lang.NoSuchFieldError: RELEASE; Stack trace: org.checkerframework.javacutil.PluginUtil.getReleaseValue(PluginUtil.java:617)
  org.checkerframework.framework.stub.StubTypes.<init>(StubTypes.java:81)
  org.checkerframework.framework.type.AnnotatedTypeFactory.<init>(AnnotatedTypeFactory.java:397)
  org.checkerframework.framework.type.GenericAnnotatedTypeFactory.<init>(GenericAnnotatedTypeFactory.java:202)
  org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory.<init>(KeyForAnnotatedTypeFactory.java:65)
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:275)
  org.checkerframework.common.basetype.BaseTypeVisitor.createTypeFactory(BaseTypeVisitor.java:261)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:220)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:209)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:224)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:85)
  org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:904)
  org.checkerframework.common.basetype.BaseTypeChecker.initChecker(BaseTypeChecker.java:100)
  org.checkerframework.common.basetype.BaseTypeChecker.initChecker(BaseTypeChecker.java:91)
  org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:860)
  org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:157)
  com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
  com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1342)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1296)
  com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
  com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
  com.sun.tools.javac.main.Main.compile(Main.java:523)
  com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
  com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
  org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
  org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
  org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1134)
  org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:187)
  org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
  org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
  org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
  org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
  org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
  org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:498)
  org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
  org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
  org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
  org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
  org.codehaus.classworlds.Launcher.main(Launcher.java:47)
MiguelMunoz
  • 4,548
  • 3
  • 34
  • 51
  • 1. The [Checker Framework Manual mentions NoSuchFieldError](https://checkerframework.org/manual/#troubleshooting-class-file-not-found); did you investigate that? 2. Please provide a [MWE](https://stackoverflow.com/help/minimal-reproducible-example). Your Tango project does not build for me, probably because of the `` in the Tango project's `pom.xml` that hard-codes a local path without populating that path. – mernst Jan 19 '20 at 04:52
  • Yes, I checked those out. Those NoSuchFieldErrors were about other missing fields. The conditions to create those problems weren't in my project. – MiguelMunoz Jan 20 '20 at 00:20
  • Please provide a MWE of compilable code. Without that, no one can answer your question. – mernst Jan 20 '20 at 14:50
  • Not sure what MWE stands for, but the defect may be reproduced using the two repositories mentioned in the original post. – MiguelMunoz Jan 20 '20 at 17:43
  • Link is in my first comment, which also notes that the projects you gave *do not compile*. – mernst Jan 20 '20 at 21:03
  • I'm sorry. I should have been more clear. (I will update the description to reflect this.) Neither the Skeleton project, nor the Tango project will compile, because of the defect described here. In each project, if you go to the pom.xml file and comment out the annotation processor (in the maven-compiler-plugin), they will compile successfully. – MiguelMunoz Jan 21 '20 at 02:30
  • Here's a URL for the MWE: https://github.com/SwingGuy1024/CheckerNoSuchFieldErrorBug – MiguelMunoz Jan 21 '20 at 02:52
  • To be clear, this new MWE will also not compile, and that's the issue I'm presenting here. When I remove the annotation processor from the build process, they compile fine, but they should compile with the annotation processor as well. – MiguelMunoz Jan 22 '20 at 01:05
  • As noted in point (2) of the first comment of this thread, your `pom.xml` file uses a hard-coded local path without putting anything at that path, leading to a `The following artifacts could not be resolved` error. Please use the [instructions in the Checker Framework manual](https://checkerframework.org/manual/#maven). So far the only problem is that you are not following the instructions. – mernst Jan 22 '20 at 22:51
  • I just changed the MWE to conform to the instructions in the checker framework manual. It still doesn't build, and it still has the same problem. (Incidentally, it would be more helpful if the installation instructions tell you to define the CHECKERFRAMEWORK environment variable.) – MiguelMunoz Jan 23 '20 at 00:31

1 Answers1

1

The problem is an incorrect pom.xml file, caused by not following the instructions in the Checker Framework Manual.

Even after multiple fixes (see comments on the original post), the pom.xml file contains this nonsense line that overrides a correct line earlier in the file:

        <errorProneJavac>.m2/repository/com/google/errorprone/${checkerVersion}:javac:jar</errorProneJavac>

When that line is present, the build yields java.lang.NoSuchFieldError: RELEASE.

Removing that line (that is, following the instructions in the manual) makes the project build.

Here is a diff that cleans up some of the wrong parts of the pom.xml file.

mernst
  • 7,437
  • 30
  • 45
  • I have discovered one additional requirement to avoid this error. I needed to set the JAVA_HOME environment variable to the java 8 JDK. That, with the change described here, was enough to make this problem go away. I was maven from inside my IntelliJ IDE. Even though I had set the maven runner to JDK 1.8, it was still giving me this error message. I needed to additionally specify JAVA_HOME in the IDE's environment variables to fix my build. – MiguelMunoz Jan 29 '20 at 21:23
  • @mernst It's a shame you deleted the linked repository :P – Mateusz Drost Mar 21 '23 at 16:07
  • @MateuszDrost The repository was not mine, but belonged to the orginal poster, MiguelMunoz. I'm sorry he deleted it, but I have no control over that. – mernst Mar 21 '23 at 22:00