error-prone icon indicating copy to clipboard operation
error-prone copied to clipboard

Lombok causes an IllegalArgumentException in SameNameButDifferent

Open benjamineckstein opened this issue 5 years ago • 3 comments

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

benjamineckstein avatar Apr 08 '21 07:04 benjamineckstein

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>

Trentondmiller avatar Oct 29 '21 20:10 Trentondmiller

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.

AlexRogalskiy avatar Nov 08 '21 09:11 AlexRogalskiy

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.

cushon avatar Apr 14 '22 20:04 cushon