FieldCanBeFinal - IllegalArgumentException (regression)
ben-manes opened this issue · comments
/Users/ben/projects/caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java:16: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
package com.github.benmanes.caffeine.cache;
^
Please report this at https://github.com/google/error-prone/issues/new and include the following:
error-prone version: 2.12.1
BugPattern: FieldCanBeFinal
Stack Trace:
java.lang.RuntimeException: java.lang.IllegalArgumentException: /Users/ben/projects/caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:163)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:370)
at com.google.errorprone.fixes.SuggestedFixes$FixCompiler.compile(SuggestedFixes.java:1372)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1300)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1260)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1242)
at com.google.errorprone.bugpatterns.FieldCanBeFinal.lambda$matchCompilationUnit$0(FieldCanBeFinal.java:238)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.google.errorprone.bugpatterns.FieldCanBeFinal.matchCompilationUnit(FieldCanBeFinal.java:236)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:555)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
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)
Seems to be fixed in 2.13.1
package com.github.benmanes.caffeine.cache;
^
Please report this at https://github.com/google/error-prone/issues/new and include the following:
error-prone version: 2.13.1
BugPattern: FieldCanBeFinal
Stack Trace:
java.lang.RuntimeException: java.lang.IllegalArgumentException: /Users/ben/projects/caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:163)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:370)
at com.google.errorprone.fixes.SuggestedFixes$FixCompiler.compile(SuggestedFixes.java:1372)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1300)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1260)
at com.google.errorprone.fixes.SuggestedFixes.compilesWithFix(SuggestedFixes.java:1242)
at com.google.errorprone.bugpatterns.FieldCanBeFinal.lambda$matchCompilationUnit$0(FieldCanBeFinal.java:238)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.google.errorprone.bugpatterns.FieldCanBeFinal.matchCompilationUnit(FieldCanBeFinal.java:236)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:555)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
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)
The underlying exception I'm seeing is:
Caused by: java.lang.IllegalArgumentException: ./caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java
at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.asPath(JavacFileManager.java:1189)
at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.contains(JavacFileManager.java:1115)
at java.compiler@11.0.13/javax.tools.ForwardingJavaFileManager.contains(ForwardingJavaFileManager.java:212)
at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager.contains(ClientCodeWrapper.java:331)
at jdk.compiler/com.sun.tools.javac.main.DelegatingJavaFileManager.contains(DelegatingJavaFileManager.java:173)
at jdk.compiler/com.sun.tools.javac.main.DelegatingJavaFileManager.contains(DelegatingJavaFileManager.java:173)
at jdk.compiler/com.sun.tools.javac.comp.Modules.checkSourceLocation(Modules.java:534)
at jdk.compiler/com.sun.tools.javac.comp.Modules.setCompilationUnitModules(Modules.java:524)
at jdk.compiler/com.sun.tools.javac.comp.Modules.enter(Modules.java:267)
at jdk.compiler/com.sun.tools.javac.comp.Modules.initModules(Modules.java:233)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.initModules(JavaCompiler.java:1046)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.enter(JavacTaskImpl.java:333)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.analyze(JavacTaskImpl.java:386)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$analyze$1(JavacTaskImpl.java:370)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
... 184 more
The failure suggests it's not seeing a PathFileObject
:
https://github.com/openjdk/jdk/blob/e5041ae3d45b43be10d5da747d773882ebf0482b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java#L1184-L1188
From ForwardingJavaFileManager
in the stack trace, I wonder if it's seeing a Forwarding*
file object, and ForwardingJavaFileManager
should be overriding contains
and maybe doing some explicit unwrapping.
I'm suspicious that either:
-
this will return file objects that don't match the installed file manager, if a custom filemanager has been installed:
-
these
SimpleJavaFileObject
s don't match the assumptions in the module-handling code:
I think it should be possible to have a regression test for this that exercises the compilesWithFix
logic in a modular compilation.