error-prone: 'An illegal reflective access operation has occurred' warnings

The warning:

Changes detected - recompiling the module!
Compiling 8 source files to /home/my_stuff/target/classes
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.errorprone.bugpatterns.FutureReturnValueIgnored (file:/my_home/.m2/repository/com/google/errorprone/error_prone_core/2.3.2/error_prone_core-2.3.2.jar) to field com.sun.tools.javac.code.Type$StructuralTypeMapping$4.this$0
WARNING: Please consider reporting this to the maintainers of com.google.errorprone.bugpatterns.FutureReturnValueIgnored
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
$ java --version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

Java code that (rightfully) triggers the warning:

@SuppressWarnings("FutureReturnValueIgnored")
private void schedule(Runnable runnable, long delayMs) {
    try {
        scheduledExecutorService.schedule(runnable, delayMs, TimeUnit.MILLISECONDS);
    } catch (RejectedExecutionException ex) {
        // shutting down, no more checks
    }
}

I’m using the maven plugin as such:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>11</release>
        <debug>true</debug>
        <showDeprecation>true</showDeprecation>
        <showWarnings>true</showWarnings>
        <compilerArgument>-parameters</compilerArgument>
        <compilerArgs>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
            <arg>-Werror</arg>
            <arg>-XDcompilePolicy=simple</arg>
            <arg>-Xplugin:ErrorProne</arg> 
        </compilerArgs>
        <annotationProcessorPaths>
            <path>
                <groupId>com.google.errorprone</groupId>
                <artifactId>error_prone_core</artifactId>
                <version>2.3.2</version>
            </path>
        </annotationProcessorPaths> 
    </configuration>
</plugin>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@tbroyer if the plugin can add them by default, that SGTM. I was planning to update the release instructions in time for JDK 16 to mention this also.

I just released v2.0.0 of the net.ltgt.errorprone plugin that does just that.

In JDK 16 EA (which I’m not sure is being used in https://github.com/google/error-prone/issues/1157#issuecomment-769260477, but noting here for posterity), the module access checks have been upgraded by JEP 396: Strongly Encapsulate JDK Internals by Default.

I don’t currently know a better way to use Error Prone on JDK 16 than passing --illegal-access=permit, or else:

--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

Example of updating a maven build with this flags: https://github.com/google/turbine/commit/622b59136c480a9aeca3fd6b4cc433c87777f8bd

Related: #1158

If --add-opens doesn’t work anymore on JDK 13, one could still disable that one check of error-prone using -Xep:FutureReturnValueIgnored:OFF.

I pushed a change to update the installation docs for JDK 16, and to also mention line continuations in the flag docs: 038d3dc

@cushon I think there was an “opens” argument missing. I had to add -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED in order to make it work for our project: https://github.com/dropwizard/dropwizard/pull/3788/commits/28a92835b6538f39d83dee81979cac5f64acf6af

Failed GitHub workflow run: https://github.com/dropwizard/dropwizard/runs/2130657086#step:8:1666

Full error message with stacktrace
Error:  /home/runner/work/dropwizard/dropwizard/dropwizard-lifecycle/src/test/java/io/dropwizard/lifecycle/setup/LifecycleEnvironmentTest.java:[59,63] error: An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:
  
     error-prone version: 2.5.1
     BugPattern: FutureReturnValueIgnored
     Stack Trace:
     java.lang.reflect.InaccessibleObjectException: Unable to make field final com.sun.tools.javac.code.Type$StructuralTypeMapping com.sun.tools.javac.code.Type$StructuralTypeMapping$4.this$0 accessible: module jdk.compiler does not "opens com.sun.tools.javac.code" to unnamed module @1efee8e7
  	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
  	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
  	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
  	at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
  	at com.google.errorprone.bugpatterns.AbstractReturnValueIgnored.getSubst(AbstractReturnValueIgnored.java:435)
  	at com.google.errorprone.bugpatterns.AbstractReturnValueIgnored.getResolvedGenerics(AbstractReturnValueIgnored.java:418)
  	at com.google.errorprone.bugpatterns.AbstractReturnValueIgnored.checkLostType(AbstractReturnValueIgnored.java:369)
  	at com.google.errorprone.bugpatterns.AbstractReturnValueIgnored.matchMethodInvocation(AbstractReturnValueIgnored.java:130)
  	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:450)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:747)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1761)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:94)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitVariable(TreeScanner.java:229)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:886)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1001)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:94)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:109)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:254)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:521)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1059)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:94)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:212)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:741)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:925)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:94)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:109)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:117)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:193)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:549)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:832)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:109)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:117)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:148)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:561)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:151)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:603)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:60)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
  	at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
  	at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:152)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1421)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1368)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
  	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)

Thanks @tbroyer, using line continuations works for me with <fork>true</fork>.

I pushed a change to update the installation docs for JDK 16, and to also mention line continuations in the flag docs: https://github.com/google/error-prone/commit/038d3dc2829b950226eff3c84b2da94986f0b285

When using <fork>true</fork>, Maven (plexus-compiler actually) will use an argument file, so it’s using Javac’s own parsing rules, where you need to use line-continuations for multiline arguments; i.e. end your lines with a \. (Disclaimer: I haven’t actually tested it, only read the JDK’s code)