Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.16.0 does not work with JDK16 in maven project #4805

Closed
pzygielo opened this issue Jul 14, 2021 · 7 comments
Closed

3.16.0 does not work with JDK16 in maven project #4805

pzygielo opened this issue Jul 14, 2021 · 7 comments

Comments

@pzygielo
Copy link

Commands:

$ # clone the reproducer
$ git clone --branch=jdk16 git://github.com/pzrep/checker-jdk16
...
$ cd checker-jdk16
$
$ # set envvar for profiles activation
$ export COMPILER=javac+checker
$
$ # Detect assignment on JDK15
$ echo $JAVA_HOME
/usr/local/jdk-15
$ javac -version
javac 15.0.2
$ java -version
openjdk version "15.0.2" 2021-01-19
OpenJDK Runtime Environment (build 15.0.2+7-27)
OpenJDK 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
$ ./mvnw clean verify
...
[WARNING] .../checker-jdk16/src/main/java/pzrep/CheckerIssue.java:[10,21] [assignment] incompatible types in assignment.
  found   : null (NullType)
  required: @Initialized @NonNull String
...
[INFO] BUILD SUCCESS
...
$
$ # crash on JDK16
$ echo $JAVA_HOME
/usr/local/jdk-16
$ javac -version
javac 16.0.1
$ java -version
java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
$ ./mvnw clean verify
...
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.034 s
[INFO] Finished at: 2021-07-14T10:23:00+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project checker-jdk16: Compilation failure -> [Help 1]

Inputs

At https://github.com/pzrep/checker-jdk16

Outputs

Key outputs included in Commands above

Expectation

My expectation is that checker 3.16.0 runs succesfully with JDK16.


It looks that prev 3.15.0 fails with similar error when executed with JVM 15.
Current 3.16.0 works with JDK15 (with warning Use JDK 8, 11, or 16 to run the Checker Framework. You are using version 15) and detects violations, but fails on JDK16.

@mernst
Copy link
Member

mernst commented Jul 14, 2021

Thanks for submitting a bug report. I'm sorry you are having trouble.

I appreciate you providing a Maven project. Unfortunately, I cannot reproduce your problem.

When I use JDK 11 or JDK 16, running ./mvnw clean verify produces no error.
(I didn't try JDK 15 since it is no longer supported.)
The complete output appears at the end of this message.

When using JDK 11 or JDK 16 and running javac -processor nullness CheckerIssue.java directly (without using Maven), I get the expected output for both JDKs:

CheckerIssue.java:10: error: [assignment] incompatible types in assignment.
  private String r = null;
                     ^
  found   : null (NullType)
  required: @Initialized @NonNull String

Since everything works for me outside Maven, but does not work within Maven, I suspect there is a problem with the Maven buildfile. I'm not a Maven expert, so I cannot provide specific advice, but I'm happy to run commands that will help you diagnose the Maven build so that I can reproduce your problem. (If the Checker Framework manual's Maven instructions are incorrect, accept my apologies, and we'll fix that.)

Here are the results of my runs of Maven:

% git clone --branch=jdk16 git://github.com/pzrep/checker-jdk16
Cloning into 'checker-jdk16'...
remote: Enumerating objects: 43, done.        
remote: Counting objects: 100% (43/43), done.        
remote: Compressing objects: 100% (26/26), done.        
remote: Total 43 (delta 8), reused 40 (delta 5), pack-reused 0        
Receiving objects: 100% (43/43), 11.99 KiB | 944.00 KiB/s, done.
Resolving deltas: 100% (8/8), done.
% git show
commit dcf922251a56eba90a537e2d79ea0b94f487b5f0 ...
% java -version
openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.10+9-LTS, mixed mode, sharing)
% ./mvnw clean verify
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< pzrep:checker-jdk16 >-------------------------
[INFO] Building checker-jdk16 1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ checker-jdk16 ---
[INFO] Deleting /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target
[INFO] 
[INFO] --- maven-help-plugin:3.2.0:active-profiles (default) @ checker-jdk16 ---
[INFO] 
Active Profiles for Project 'pzrep:checker-jdk16:jar:1-SNAPSHOT':

The following profiles are active:

 - target:11 (source: pzrep:checker-jdk16:1-SNAPSHOT)



[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ checker-jdk16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ checker-jdk16 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ checker-jdk16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ checker-jdk16 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ checker-jdk16 ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ checker-jdk16 ---
[INFO] Building jar: /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target/checker-jdk16-1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.510 s
[INFO] Finished at: 2021-07-14T10:21:21-07:00
[INFO] ------------------------------------------------------------------------
% 
% java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
% ./mvnw clean verify
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< pzrep:checker-jdk16 >-------------------------
[INFO] Building checker-jdk16 1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ checker-jdk16 ---
[INFO] Deleting /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target
[INFO] 
[INFO] --- maven-help-plugin:3.2.0:active-profiles (default) @ checker-jdk16 ---
[INFO] 
Active Profiles for Project 'pzrep:checker-jdk16:jar:1-SNAPSHOT':

The following profiles are active:

 - target:16 (source: pzrep:checker-jdk16:1-SNAPSHOT)



[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ checker-jdk16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ checker-jdk16 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ checker-jdk16 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ checker-jdk16 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ checker-jdk16 ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ checker-jdk16 ---
[INFO] Building jar: /homes/gws/mernst/tmp/cf-issue-4805/checker-jdk16/target/checker-jdk16-1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.630 s
[INFO] Finished at: 2021-07-14T10:21:49-07:00
[INFO] ------------------------------------------------------------------------
% 

@pzygielo
Copy link
Author

Here are the results of my runs of Maven:

In my reproducer, it's important to have COMPILER set as in my steps or

$ COMPILER=javac+checker ./mvnw clean verify
...
The following profiles are active:

 - target:11 (source: pzrep:checker-jdk16:1-SNAPSHOT)
 - compiler:javac+checker (source: pzrep:checker-jdk16:1-SNAPSHOT)
 - compiler:javac+checker-jdk9+ (source: pzrep:checker-jdk16:1-SNAPSHOT)

(or activate checker profiles in CLI).

@pzygielo
Copy link
Author

I'm not a maven expert myself. But here's what I get when I run javac directly with JDK15

$ javac -version ; javac -d target/classes -classpath $HOME/.m2/repository/org/checkerframework/checker-qual/3.16.0/checker-qual-3.16.0.jar: -sourcepath src/main/java src/main/java/pzrep/CheckerIssue.java -processor org.checkerframework.checker.nullness.NullnessChecker -processorpath $HOME/.m2/repository/org/checkerframework/checker/3.16.0/checker-3.16.0.jar:$HOME/.m2/repository/org/checkerframework/checker-qual/3.16.0/checker-qual-3.16.0.jar:$HOME/.m2/repository/org/checkerframework/checker-util/3.16.0/checker-util-3.16.0.jar: -g --release 15 -encoding UTF-8 -Awarns
javac 15.0.2
warning: Use JDK 8, 11, or 16 to run the Checker Framework.  You are using version 15.
src/main/java/pzrep/CheckerIssue.java:10: warning: [assignment] incompatible types in assignment.
  private String r = null;
                     ^
  found   : null (NullType)
  required: @Initialized @NonNull String
2 warnings

and JDK 16

$ javac -version ; javac -d target/classes -classpath $HOME/.m2/repository/org/checkerframework/checker-qual/3.16.0/checker-qual-3.16.0.jar: -sourcepath src/main/java src/main/java/pzrep/CheckerIssue.java -processor org.checkerframework.checker.nullness.NullnessChecker -processorpath $HOME/.m2/repository/org/checkerframework/checker/3.16.0/checker-3.16.0.jar:$HOME/.m2/repository/org/checkerframework/checker-qual/3.16.0/checker-qual-3.16.0.jar:$HOME/.m2/repository/org/checkerframework/checker-util/3.16.0/checker-util-3.16.0.jar: -g --release 15 -encoding UTF-8 -Awarns
javac 16.0.1


An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.IllegalAccessError: class org.checkerframework.javacutil.AbstractTypeProcessor (in unnamed module @0x5f341870) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x5f341870
	at org.checkerframework.javacutil.AbstractTypeProcessor.init(AbstractTypeProcessor.java:97)
	at org.checkerframework.framework.source.SourceChecker.init(SourceChecker.java:529)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:702)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:829)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:925)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1269)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1384)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1261)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:935)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

@pzygielo
Copy link
Author

Probably I need to add more opens and exports then (https://checkerframework.org/manual/#javac-jdk11).

@pzygielo
Copy link
Author

Probably I need to add more opens and exports

Indeed - it was all my fault of not re-reading CF manual on upgrade. Adding remaining exports makes the maven build project successfully.

@mernst - thank you for checking and pointing to direct call of javac. It shows the reason, while the exception from processor in maven build - even with -X flag - is kept in secret:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.306 s
[INFO] Finished at: 2021-07-14T21:32:48+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project checker-jdk16: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project checker-jdk16: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1224)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:187)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
[ERROR] 

@pzygielo
Copy link
Author

while the exception from processor in maven build - even with -X flag - is kept in secret:

like this https://issues.apache.org/jira/browse/MCOMPILER-434

@mernst
Copy link
Member

mernst commented Jul 14, 2021

I'm glad this is working for you now! Please let us know if you have any other problems.

while the exception from processor in maven build - even with -X flag - is kept in secret:

like this https://issues.apache.org/jira/browse/MCOMPILER-434

This is a nasty bug! I have mentioned this bug in the Checker Framework Manual. If you have any other suggestions about the documentation, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants