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

LombokHandler com.sun.tools.javac.util.Filter usage #794

Closed
KyleBS opened this issue Jul 28, 2023 · 1 comment · Fixed by #795
Closed

LombokHandler com.sun.tools.javac.util.Filter usage #794

KyleBS opened this issue Jul 28, 2023 · 1 comment · Fixed by #795

Comments

@KyleBS
Copy link

KyleBS commented Jul 28, 2023

Hi all,

After updating a JDK17-based project to the latest version of NullAway to 0.10.11 I started getting the following exception:

> Task :compileJava                                                                                                                                                                                                            
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.20.0                                                                                                                                                                                               
     BugPattern: (see stack trace)                                                                                                                                                                                             
     Stack Trace:                                                                                                                                                                                                              
     java.lang.NoClassDefFoundError: com/sun/tools/javac/util/Filter                                                                                                                                                           
        at com.uber.nullaway.handlers.LombokHandler.isLombokMethodWithMissingNullableAnnotation(LombokHandler.java:50)                                                                                                         
        at com.uber.nullaway.handlers.LombokHandler.onOverrideMethodReturnNullability(LombokHandler.java:90)                                                                                                                   
        at com.uber.nullaway.handlers.CompositeHandler.onOverrideMethodReturnNullability(CompositeHandler.java:133)                                                                                                            
        at com.uber.nullaway.NullAway.getMethodReturnNullness(NullAway.java:822)                                                                                                                                               
        at com.uber.nullaway.NullAway.checkReturnExpression(NullAway.java:840)                                                                                                                                                 
        at com.uber.nullaway.NullAway.matchReturn(NullAway.java:386)                                                                                                                                                           
        at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)                                                                                                                         
        at com.google.errorprone.scanner.ErrorProneScanner.visitReturn(ErrorProneScanner.java:816)                                                                                                                             
        at com.google.errorprone.scanner.ErrorProneScanner.visitReturn(ErrorProneScanner.java:150)                                                                                                                             
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1717)                                                                                                                                      
        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:111)                                                                                                                                             
        at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:272)                                                                                                                                       
        at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:520)                                                                                                                              
        at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:150)                                                                                                                              
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1103)                                                                                                                                       
        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:96)                                                                                                                                     
        at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:224)                                                                                                                                      
        at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:740)                                                                                                                             
        at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:150)                                                                                                                             
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:953)                                                                                                                                   
        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:96)                                                                                                                                     
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)                                                                                                                                             
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)                                                                                                                                    
        at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:203)                                                                                                                                       
        at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:548)                                                                                                                              
        at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:150)                                                                                                                              
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:860)                                                                                                                                    
        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:111)                                                                                                                                             
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)                                                                                                                                    
        at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:152)                                                                                                                             
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:560)                                                                                                                    
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)                                                                                                                    
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)                                                                                                                              
        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:156)                                                                                                                                      
        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:1394)                                                                                                                                     
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1341)            
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)                                                                                                                                   
        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.gradle.internal.compiler.java.IncrementalCompileTask.call(IncrementalCompileTask.java:89)                                                                                                                       
        at org.gradle.api.internal.tasks.compile.AnnotationProcessingCompileTask.call(AnnotationProcessingCompileTask.java:94)                                                                                                 
        at org.gradle.api.internal.tasks.compile.ResourceCleaningCompilationTask.call(ResourceCleaningCompilationTask.java:57)                                                                                                 
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:56)                                                                                                                              
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:41)                                                                                                                              
        at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerWorkAction.execute(AbstractDaemonCompiler.java:135)                                                                                     
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)                                                                                                                                
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:49)                                                                                                                   
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:43)                                                                                                                   
        at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)                                                                                                                    
        at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:43)
        at org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:32)                                                                                                                                
        at org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:22)                                                                                                                                
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:87)                                                                                                                                      
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:56)                                                                                                                                      
        at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:138)                                                                                                                               
        at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
        at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:135)                                                                                                                                  
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                                      
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)                                                                                                                    
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                                            
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)                                                                                                                                                          
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)                                                                                                                                
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)                                                                                                                                
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)                                                                                                                                 
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)                                                                                                              
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)                                                                                                                               
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)                                                                                                                           
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)                                                                                                                           
        at java.base/java.lang.Thread.run(Thread.java:833)                                                     
  Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.util.Filter                                                                                                                                                 
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)                                                                                                                                                
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)                                                                                                                                                     
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)                                                                                                                                                     
        ... 89 more  

It looks like the Filter class was removed in JDK17:

openjdk/jdk@657f1039

With NullAway targeting JDK8 it appears that the org.openjdk.tools.javac.code.Scope.getSymbols(Filter) usage at https://github.com/uber/NullAway/blob/master/nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java#L51-L54 is to blame, with JDK17 targeting org.openjdk.tools.javac.code.Scope.getSymbols(Predicate).

ErrorProne looks like they also had to address this - google/error-prone@0c6a76d

Is this something that can be looked in to?

Thanks!
Kyle

@msridhar
Copy link
Collaborator

Thanks a lot for this report! It exposed a gap in our testing. Fix is up in #795

msridhar added a commit that referenced this issue Jul 31, 2023
…Backports (#795)

Fixes #794. Since the JDK interface change was made for JDK 17, I think
even if NullAway was built on and targeted JDK 11, we would still have
this problem. I added some hacky unit test coverage for this code so
we'd have a way to test for regressions in the future. (The new unit
test fails the `:nullaway:testJdk8` task without this change.)

We missed this problem earlier since we suppressed a warning from
`AstHelpersSuggestions`. Even though we cannot accept some of the
suggestions from that check (since we may not require a recent enough
version of Error Prone), the issues it flags can be serious. So, this PR
removes all other suppressions of that checker and fixes the warnings.
We introduce an `AstHelpersBackports` class to contain any backported
logic from `AstHelpers` to enable the fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants