google / error-prone

Catch common Java mistakes as compile-time errors
https://errorprone.info
Apache License 2.0
6.85k stars 744 forks source link

Lombok breaks NestedInstanceOfConditions and InstanceOfAndCastMatchWrongType #690

Closed davidmontoyago closed 7 years ago

davidmontoyago commented 7 years ago

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00) Java version: 1.8.0_131, vendor: Oracle Corporation Lombok version: 1.16.16

java.lang.NullPointerException
        at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:123)
        at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
        at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:478)
        at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:417)
        at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
        at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
        at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
        at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:968)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:884)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1204)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1313)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1267)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:943)
        at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
        at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
        at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137)
        at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108)
        at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118)
        at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65)
        at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne$CompilerInvoker.compile(JavacCompilerWithErrorProne.java:219)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne.performCompile(JavacCompilerWithErrorProne.java:91)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        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:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
error-prone version: 2.0.21                                                                                                                                                 
Stack Trace:                                                                                                                                                                
java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCBinary cannot be cast to com.sun.source.tree.ParenthesizedTree                                              
   at com.google.errorprone.bugpatterns.NestedInstanceOfConditions.matchIf(NestedInstanceOfConditions.java:53)                                                              
   at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:752)                                                                                   
   at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:146)                                                                                   
   at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1427)                                                                                                         
   at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)                                                                                                     
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)                                                                                                           
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)                                                                                                           
   at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)                                                                                                            
   at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248)                                                                                                      
   at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:530)                                                                                
   at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:146)                                                                                
   at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)                                                                                                      
   at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)                                                                                                     
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)                                                                                                           
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)                                                                                                           
   at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)                                                                                                    
   at com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206)                                                                                                     
   at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:898)                                                                               
   at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:146)                                                                               
   at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)                                                                                                  
   at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)                                                                                                     
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)                                                                                                           
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)                                                                                                           
   at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)                                                                                                    
   at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)                                                                                                            
   at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)                                                                                                   
   at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187)                                                                                                      
   at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:590)                                                                                
   at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:146)                                                                                
   at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)                                                                                                   
   at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)                                                                                                     
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)                                                                                                           
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)                                                                                                           
   at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)                                                                                                            
   at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)                                                                                                   
   at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)                                                                                            
   at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:605)                                                                      
   at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:146)                                                                      
   at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)                                                                                             
   at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)                                                                                                     
   at com.google.errorprone.scanner.Scanner.scan(Scanner.java:64)                                                                                                           
   at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:41)                                                                
   at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:145)                                                                                        
   at com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:120)                                                                                        
   at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1425)                                                                                                    
   at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374)                                                                                                    
   at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)                                                                                                  
   at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)                                                                                         
   at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)                                                                                        
   at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)                                                                                                   
   at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)                                                                                                     
   at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137)                                                                                     
   at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108)                                                                                     
   at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118)                                                                                             
   at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65)                                                                                          
   at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne$CompilerInvoker.compile(JavacCompilerWithErrorProne.java:219)                               
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                           
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                                         
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                 
   at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                                      
   at org.codehaus.plexus.compiler.javac.errorprone.JavacCompilerWithErrorProne.performCompile(JavacCompilerWithErrorProne.java:91)                                         
   at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825)                                                                          
   at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)                                                                                          
   at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)                                                                     
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)                                                                                       
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)                                                                                       
   at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)                                                                                       
   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:51)                                                 
   at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)                                                                               
   at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)                                                                                                        
   at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)                                                                                                        
   at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)                                                                                                          
   at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)                                                                                                              
   at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)                                                                                                               
   at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)                                                                                                                 
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                           
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                                         
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                                 
   at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                                      
   at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)                                                                                   
   at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)                                                                                           
   at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)                                                                                 
   at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)                                                                                             
goostleek commented 7 years ago

I'm experiencing the same issue. I do not include the stack trace as it's identical.

------------------------------------------------------------
Gradle 4.0.2
------------------------------------------------------------

Build time:   2017-07-26 15:04:56 UTC
Revision:     108c593aa7b43852f39045337ee84ee1d87c87fd

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Windows 10 10.0 amd64

error-prone version: 2.0.21 lombok version: 1.16.18

cushon commented 7 years ago

Thanks for the report. Can you provide a self-contained example that reproduces the crash?

goostleek commented 7 years ago

Yes @cushon, please use this MWE to reproduce the issue.

JamesMcMahon commented 7 years ago

Issue is still present in 2.1.1. If you replace @Data with

@RequiredArgsConstructor
@EqualsAndHashCode 

It blows up. Specifically it seems like the issue is due to @EqualsAndHashCode.

This makes Lombok and Error Prone a non-starter. Are there any updates on workarounds / fixing this?

cushon commented 7 years ago

A fix is in progress.

You can disable the crashing check as a work-around: -Xep:NestedInstanceOfConditions:OFF

cushon commented 7 years ago

(Another option is to use @AutoValue to generate value classes instead of Lombok.)

JamesMcMahon commented 7 years ago

-Xep:NestedInstanceOfConditions:OFF didn't work for me. I'll have to try out the fix once it's released.

Thanks @cushon!

thefallentree commented 7 years ago

has the fix been released ? What's the targeted version?

thefallentree commented 7 years ago

BTW lombok @Slf4j annotation also break stuff

bhagyas commented 7 years ago

Continues to happen.

jasonzhao3 commented 6 years ago

+1 happens to me as well

darren-rose commented 6 years ago

+1

@Data ^ Please report this at https://github.com/google/error-prone/issues/new and include the following:

 error-prone version: 2.1.1
 Stack Trace:
 java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCBinary cannot be cast to com.sun.source.tree.ParenthesizedTree
    at com.google.errorprone.bugpatterns.NestedInstanceOfConditions.matchIf(NestedInstanceOfConditions.java:53)
    at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:752)
    at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:146)
    at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1427)
    at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)
    at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
    at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248)
    at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:530)
    at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:146)
    at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
    at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)
    at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
    at com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206)
    at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:898)
    at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:146)
    at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
    at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)
    at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
    at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
    at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
    at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187)
    at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:590)
    at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:146)
    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
    at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:82)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:42)
    at com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
    at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
    at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
    at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:605)
    at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:146)
    at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
    at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
    at com.google.errorprone.scanner.Scanner.scan(Scanner.java:64)
    at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:41)
    at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:145)
    at com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:120)
wcp1231 commented 6 years ago

error-prone version: 2.1.3 Continues to happen.

cushon commented 6 years ago

@wcp1231 can you file a new bug and include a self-contained example that reproduces the problem?

wcp1231 commented 6 years ago

@cushon Yes, this MWE

cushon commented 6 years ago

@wcp1231 that is a different issue: #780.

wcp1231 commented 6 years ago

@cushon yes, when I add args -Xep:NestedInstanceOfConditions:OFF and -Xep:ParameterName:OFF it works. So... It is not a bug?

cushon commented 6 years ago

It's a bug, but it's #780 and not this bug. Suppressing ParameterName and updating the lombok version to 1.16.18 allow that example to build.

wcp1231 commented 6 years ago

Ok, thx

rspilker commented 6 years ago

Can I help?

eankit commented 1 year ago

@cushon is this issue fixed?