error-prone: lombok causes an IndexOutOfBoundsException in UnusedVariable
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"]
}
}
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 10
- Comments: 19 (2 by maintainers)
See https://errorprone.info/docs/flags#maven
You need to pass
-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCodeas a single<arg>@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 https://github.com/rzwitserloot/lombok/issues/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 theFileObjectand adjust the positions of other AST nodes in the file?The other thing I can think of is that if
@lombok.Generatedwas 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.Generatedannotation. Is that expected?@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.