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

lombok causes an IndexOutOfBoundsException in UnusedVariable #1250

Open
mrt181 opened this issue Mar 26, 2019 · 19 comments
Open

lombok causes an IndexOutOfBoundsException in UnusedVariable #1250

mrt181 opened this issue Mar 26, 2019 · 19 comments
Labels

Comments

@mrt181
Copy link

mrt181 commented Mar 26, 2019

Description of the problem / feature request:

./gradlew clean compileJava throws this error

Service.java:1: error: An unhandled exception was thrown by the Error Prone static analysis plugin.                                                    
package io.mine.service.grpc;
^
     Please report this at https://github.com/google/error-prone/issues/new and include the following:
	 
     error-prone version: 2.3.3
     BugPattern: UnusedVariable
     Stack Trace:
     java.lang.IndexOutOfBoundsException
        at java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:580)
        at java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:42)
        at com.google.errorprone.fixes.SuggestedFixes.replaceIncludingComments(SuggestedFixes.java:1021)
        at com.google.errorprone.bugpatterns.UnusedVariable.buildUnusedVarFixes(UnusedVariable.java:387)
        at com.google.errorprone.bugpatterns.UnusedVariable.matchCompilationUnit(UnusedVariable.java:239)
        at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:433)
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:541)
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)

Feature requests: what underlying problem are you trying to solve with this feature?

none, its applied by error-prone 2.3.3

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

What version of Error Prone are you using?

errorproneJavacVersion = "9+181-r4173-1"
errorproneVersion = "2.3.2"
errorpronePluginVersion = "0.7.1"

openjdk version "1.8.0_192"

Have you found anything relevant by searching the web?

reverting back to 2.3.2 fixes the problem.
I tried to exclude the BugPattern but that does not work:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
        options.annotationProcessorPath = configurations.errorprone
        options.errorprone.enabled = true
        options.errorprone.disableWarningsInGeneratedCode = true
        options.errorprone.excludedPaths = ".*/build/gen.*/.*"
        options.errorprone.errorproneArgs = ["-Xep:ParameterName:OFF",
                                            "Xep:UnusedVariable:OFF"]
    }
}
@bbzg
Copy link

bbzg commented Apr 7, 2019

Title says 2.3.2 but should say 2.3.3?

I am also seeing this issue on 2.3.3, fixed by reverting to 2.3.2.

@mrt181 mrt181 changed the title 2.3.2 fails with new UnusedVariable message 2.3.3 fails with new UnusedVariable message Apr 7, 2019
@martinschaef
Copy link

I can unblock myself by adding -Xep:ParameterName:OFF as suggested in:
#780 (comment)

@mrt181
Copy link
Author

mrt181 commented May 21, 2019

-Xep:ParameterName:OFF does not work for me

This works though

gradle.projectsEvaluated {
    tasks.withType(JavaCompile).configureEach {
        options.encoding = "UTF-8"
        options.annotationProcessorPath = configurations.errorprone
        options.errorprone.disableWarningsInGeneratedCode = true
        options.errorprone.excludedPaths = ".*/build/gen.*/.*"
        options.errorprone {
            disable("ParameterName")
            disable("UnusedVariable")
        }
    }
}

@cushon
Copy link
Collaborator

cushon commented Jan 19, 2021

re: #1250 (comment), if -Xep:ParameterName:OFF works around the crash it's a different bug: #780

Re-opening to track crashes related to lombok and UnusedVariable.

@cushon cushon reopened this Jan 19, 2021
@cushon cushon changed the title 2.3.3 fails with new UnusedVariable message lombok causes an IndexOutOfBoundsException in UnusedVariable Jan 19, 2021
@cushon
Copy link
Collaborator

cushon commented Jan 19, 2021

import lombok.extern.flogger.Flogger;

@Flogger
public class I1250 {}
javac   -XDcompilePolicy=simple   -processorpath lombok-1.18.16.jar:error_prone_core-2.5.1-with-dependencies.jar:dataflow-shaded-3.7.1.jar:jFormatString-3.0.0.jar   '-Xplugin:ErrorProne -Xep:UnusedVariable:ERROR -Xep:ReferenceEquality:OFF' -cp lombok-1.18.16.jar:flogger-0.5.1.jar I1250.java
import lombok.extern.flogger.Flogger;
^

     error-prone version: 2.5.1
     BugPattern: UnusedVariable
     Stack Trace:
     java.lang.IndexOutOfBoundsException: Range [54, -1) out of bounds for length 70
  	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
  	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:76)
  	at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:295)
  	at java.base/java.util.Objects.checkFromToIndex(Objects.java:385)
  	at java.base/java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:677)
  	at java.base/java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:44)
  	at com.google.errorprone.VisitorState.getOffsetTokens(VisitorState.java:585)
  	at com.google.errorprone.fixes.SuggestedFixes.replaceIncludingComments(SuggestedFixes.java:1547)
  	at com.google.errorprone.bugpatterns.UnusedVariable.buildUnusedVarFixes(UnusedVariable.java:381)

@rspilker
Copy link

I am a Lombok maintainer. If there's anything we can do to help, please let us know. (apart from not generating a field that is not used...)

@cushon
Copy link
Collaborator

cushon commented Jan 19, 2021

@rspilker I think most of the crashes are happening because the source positions for the AST nodes lombok adds are incomplete (e.g. missing end positions), or they get out of sync with the source (e.g. from compilationUnit.getSourceFile().getCharContent(...)). I think projectlombok/lombok#2691 would help, although I'm not sure it's enough by itself to prevent crashes, unless you're also able to update the contents of the FileObject and adjust the positions of other AST nodes in the file?

The other thing I can think of is that if @lombok.Generated was generated by default. We could rely on it to not process some of the generated code, which would also avoid crashes and false positives.

For @lombok.Generated, I think I'm seeing cases where lombok is editing AST nodes (which then don't have end positions) outside of regions that have a @lombok.Generated annotation. Is that expected?

@Rawi01
Copy link

Rawi01 commented Jan 24, 2021

@cushon Thanks for adding some code to ignore generated stuff, that should fix most problems. Meanwhile I started to add start and end positions for everything lombok generates. If that is finished and merged all remaining problmes should be solved.

@ParSal123
Copy link

How do I add that setting in Maven?

See https://errorprone.info/docs/flags#maven

You need to pass -Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode as a single <arg>

This didn't work for me on 2.19.1 with lombok 1.18.22.

An unhandled exception was thrown by the Error Prone static analysis plugin.
[ERROR]      Please report this at https://github.com/google/error-prone/issues/new and include the following:
[ERROR]
[ERROR]      error-prone version: 2.19.1
[ERROR]      BugPattern: UnusedVariable
[ERROR]      Stack Trace:
[ERROR]      java.lang.IndexOutOfBoundsException: Range [573, 541) out of bounds for length 2941
[ERROR]         at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
[ERROR]         at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:76)
[ERROR]         at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:313)
[ERROR]         at java.base/java.util.Objects.checkFromToIndex(Objects.java:385)
[ERROR]         at java.base/java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:664)
[ERROR]         at java.base/java.nio.HeapCharBuffer.subSequence(HeapCharBuffer.java:44)
[ERROR]         at com.google.errorprone.VisitorState.getOffsetTokens(VisitorState.java:607)
[ERROR]         at com.google.errorprone.fixes.SuggestedFixes.replaceIncludingComments(SuggestedFixes.java:1667)
[ERROR]         at com.google.errorprone.bugpatterns.UnusedVariable.buildUnusedVarFixes(UnusedVariable.java:409)
[ERROR]         at com.google.errorprone.bugpatterns.UnusedVariable.matchCompilationUnit(UnusedVariable.java:249)
[ERROR]         at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
[ERROR]         at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:555)
[ERROR]         at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
[ERROR]         at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)
[ERROR]         at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:60)
[ERROR]         at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
[ERROR]         at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
[ERROR]         at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:156)
[ERROR]         at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1394)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1341)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)
[ERROR]         at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
[ERROR]         at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
[ERROR]         at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
[ERROR]         at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
[ERROR]         at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
[ERROR]         at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
[ERROR]         at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1134)
[ERROR]         at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:187)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:298)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR]

@ParSal123
Copy link

Actually, my bad. Forgot the lombok.addLombokGeneratedAnnotation = true.
But now I get another error. #3954
I'll add a comment there.

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

No branches or pull requests