Lombok causes an IllegalArgumentException in SameNameButDifferent
Description of the problem / feature request:
error: An unhandled exception was thrown by the Error Prone static analysis plugin.
package ....
error-prone version: 2.6.0
BugPattern: SameNameButDifferent
Stack Trace:
java.lang.IllegalArgumentException: invalid source positions (629, 593) for: NonNull
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:459)
at com.google.errorprone.VisitorState.getSourceForNode(VisitorState.java:553)
at com.google.errorprone.bugpatterns.SameNameButDifferent$1.handle(SameNameButDifferent.java:101)
at com.google.errorprone.bugpatterns.SameNameButDifferent$1.visitIdentifier(SameNameButDifferent.java:84)
at com.google.errorprone.bugpatterns.SameNameButDifferent$1.visitIdentifier(SameNameButDifferent.java:61)
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
package token;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
@JsonInclude(Include.NON_NULL)
@Builder
@Getter
public class GenerateTokenRequest {
@NonNull
private final TokenAccessLevel accessLevel;
private final boolean allowSaveAs;
private final String datasetId;
private final List<EffectiveIdentity> identities;
}
What version of Error Prone are you using?
error-prone version: 2.6.0
Have you found anything relevant by searching the web?
https://github.com/google/error-prone/issues/690
I'm getting a similar issue Java 17 Error Prone 2.9 Lombok 1.18.22 Maven Compiler Plugin 3.8.1
My error looks more like this one: https://giters.com/google/error-prone/issues/2290, but that ticket points to here.
error-prone version: 2.9.0
BugPattern: SameNameButDifferent
Stack Trace:
java.lang.NullPointerException: Cannot read field "owner" because "owner" is null
at com.google.errorprone.bugpatterns.SameNameButDifferent.getBetterImport(SameNameButDifferent.java:187)
at com.google.errorprone.bugpatterns.SameNameButDifferent.matchCompilationUnit(SameNameButDifferent.java:142)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:450)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:556)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:151)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)
I just disabled SameNameButDifferent to get past it for now (along with other conditions recommended to disable from other bugs
<arg>-Xplugin:ErrorProne -Xep:NestedInstanceOfConditions:OFF -Xep:ParameterName:OFF -Xep:SameNameButDifferent:OFF</arg>
The Bug exists indeed, but you can also use particular annotations on target elements like so:
@SuppressWarnings("SameNameButDifferent")
just to mute several errors from error-prone library.
Please re-open this or file a new bug if you're still seeing issues with Lombok and Error Prone 2.13.0 when -XepDisableWarningsInGeneratedCode is enabled.