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

Spurious "SameNameButDifferent" warning on Lombok code with @Getter and @Builder #3187

Open
hakanai opened this issue May 11, 2022 · 3 comments

Comments

@hakanai
Copy link

hakanai commented May 11, 2022

For some Lombok code with a @Getter annotation, the "SameNameButDifferent" warning is triggered with an error message that seems to suggest it's treating the other types and annotations on the field as if they are field names. (?)

Related to #2982, #3094, but different because it's now a spurious warning instead of an exception.

...\src\main\java\com\example\Person.java:13: warning: [SameNameButDifferent] The name `@Getter` refers to [javax.annotation.Nullable, java.lang.SuppressWarnings, lombok.Generated, java.lang.String] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
    @Getter
    ^
    (see https://errorprone.info/bugpattern/SameNameButDifferent)

Versions in play:

  • Lombok 1.18.24
  • ErrorProne 2.7.1, 2.13.1
  • Java 11

Repro - NOTE: This repo was for reproducing a different issue, but it exhibits this issue also. You might want to comment out the MissingSummary line in build.gradle.kts, otherwise that causes an outright failure, but you should get the warning about SameNameButDifferent in the output regardless.

@hakanai
Copy link
Author

hakanai commented May 11, 2022

What I see in the debugger before the warning is about to be emitted:

table = {HashBasedTable@13385} "{javax.annotation.Nullable={javax.annotation.Nullable=[com.sun.source.util.TreePath@59345113]}, lombok.Builder={lombok.Builder=[com.sun.source.util.TreePath@1e0e4bfc]}, lombok.Getter={lombok.Getter=[com.sun.source.util.TreePath@6102c3]}, Getter={lombok.Getter=[com.sun.source.util.TreePath@16fbb3f5, com.sun.source.util.TreePath@6d3cd4f0]}, @Getter={javax.annotation.Nullable=[com.sun.source.util.TreePath@1013300, com.sun.source.util.TreePath@97e4ef9, com.sun.source.util.TreePath@42512038, com.sun.source.util.TreePath@49c1f7d6], java.lang.SuppressWarnings=[com.sun.source.util.TreePath@41d044dd, com.sun.source.util.TreePath@3aa2c398], lombok.Generated=[com.sun.source.util.TreePath@71b97414, com.sun.source.util.TreePath@370042b2], java.lang.String=[com.sun.source.util.TreePath@74350e23]}, String={java.lang.String=[com.sun.source.util.TreePath@58a7bd3e]}, @Builder={java.lang.SuppressWarnings=[com.sun.source.util.TreePath@62047bea, com.sun.source.util.TreePath@57a4a0ca, com.sun.source.util.Tr"
 backingMap = {LinkedHashMap@13407}  size = 7
 factory = {HashBasedTable$Factory@13408} 
 columnKeySet = null
 rowMap = {StandardTable$RowMap@13409}  size = 7
  "javax.annotation.Nullable" -> {StandardTable$Row@13420}  size = 1
  "lombok.Builder" -> {StandardTable$Row@13422}  size = 1
  "lombok.Getter" -> {StandardTable$Row@13424}  size = 1
  "Getter" -> {StandardTable$Row@13426}  size = 1
  "@Getter" -> {StandardTable$Row@13428}  size = 4 👈
  "String" -> {StandardTable$Row@13430}  size = 1
  "@Builder" -> {StandardTable$Row@13432}  size = 6 👈
trimmedTable = {HashBasedTable@13752} "{@Getter={javax.annotation.Nullable=[com.sun.source.util.TreePath@14788eca, com.sun.source.util.TreePath@77061eb4, com.sun.source.util.TreePath@2589e2b7, com.sun.source.util.TreePath@23349838], java.lang.SuppressWarnings=[com.sun.source.util.TreePath@736a5c4a, com.sun.source.util.TreePath@345e0f2d], lombok.Generated=[com.sun.source.util.TreePath@5e28cf4b, com.sun.source.util.TreePath@59da79ee], java.lang.String=[com.sun.source.util.TreePath@78f3e693]}, @Builder={java.lang.SuppressWarnings=[com.sun.source.util.TreePath@24da7b99, com.sun.source.util.TreePath@2ec563e5, com.sun.source.util.TreePath@49e5dfd0, com.sun.source.util.TreePath@708209ba, com.sun.source.util.TreePath@773a280, com.sun.source.util.TreePath@2ac33c0, com.sun.source.util.TreePath@6550771a, com.sun.source.util.TreePath@57f7dd3, com.sun.source.util.TreePath@1f82b85e, com.sun.source.util.TreePath@7cd3aa5d], lombok.Generated=[com.sun.source.util.TreePath@1a5dfa7a, com.sun.source.util.TreePath@64329d07, com.sun.source.util.T"
 backingMap = {LinkedHashMap@13816}  size = 2
 factory = {HashBasedTable$Factory@13817} 
 columnKeySet = null
 rowMap = {StandardTable$RowMap@13818}  size = 2
  "@Getter" -> {StandardTable$Row@13823}  size = 4
   key = "@Getter"
   value = {StandardTable$Row@13823}  size = 4
    {Symbol$ClassSymbol@13385} "javax.annotation.Nullable" -> {ArrayList@13457}  size = 4
    {Symbol$ClassSymbol@13442} "java.lang.SuppressWarnings" -> {ArrayList@13708}  size = 2
    {Symbol$ClassSymbol@13450} "lombok.Generated" -> {ArrayList@13716}  size = 2
    {Symbol$ClassSymbol@13424} "java.lang.String" -> {ArrayList@13796}  size = 1
  "@Builder" -> {StandardTable$Row@13824}  size = 6
   key = "@Builder"
   value = {StandardTable$Row@13824}  size = 6
    {Symbol$ClassSymbol@13442} "java.lang.SuppressWarnings" -> {ArrayList@13472}  size = 10
    {Symbol$ClassSymbol@13450} "lombok.Generated" -> {ArrayList@13480}  size = 10
    {Symbol$ClassSymbol@13424} "java.lang.String" -> {ArrayList@13502}  size = 4
    {Symbol$ClassSymbol@13552} "com.example.Person.PersonBuilder" -> {ArrayList@13587}  size = 4
    {Symbol$ClassSymbol@13609} "com.example.Person" -> {ArrayList@13616}  size = 2
    {Symbol$ClassSymbol@13624} "java.lang.Override" -> {ArrayList@13810}  size = 1

@hakanai hakanai changed the title Spurious "SameNameButDifferent" warning on Lombok code with @Getter Spurious "SameNameButDifferent" warning on Lombok code with @Getter and @Builder May 11, 2022
@hakanai
Copy link
Author

hakanai commented May 11, 2022

At the first point during tree traversal, where one of the offending entries ends up in the table:

tree = {JCTree$JCIdent@13451} "Nullable"
treeSource = "@Getter"
symbol = {Symbol$ClassSymbol@13390} "javax.annotation.Nullable"

It almost seems like treeSource has just been determined incorrectly? And then "@Getter" ends up in the table where I'd expect "Nullable" instead.

So is this actually Lombok putting in the wrong start and end position for the symbol? Or is the warning coming out of the generated code, and Lombok's just pointing at the annotation which was used to generate it? Either way, it's doubly odd, because we have disabled warnings in generated code, and are still getting a warning from the generated code.

@NZhuravlev
Copy link

NZhuravlev commented Dec 14, 2022

Same here. You can also add @Slf4j to the list, which causes the same error.

tasks.withType<JavaCompile>().configureEach {
    options.errorprone.disableWarningsInGeneratedCode.set(true)
}

doesn't help.

I also get a lot of MissingSummary errors for Lombok annotations.

Versions

Lombok 1.18.24
errorprone 2.13.1

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

No branches or pull requests

2 participants