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

[BUG] Lombok + eclipse + null-analysis: full compile OK, incremental incorrect #3133

Closed
jopatai opened this issue Mar 11, 2022 · 5 comments · Fixed by #3135
Closed

[BUG] Lombok + eclipse + null-analysis: full compile OK, incremental incorrect #3133

jopatai opened this issue Mar 11, 2022 · 5 comments · Fixed by #3135
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse
Milestone

Comments

@jopatai
Copy link
Contributor

jopatai commented Mar 11, 2022

Describe the bug
When Eclipse performs an incremental build with null analysis enabled, it cannot see the annotations on Lombok generated code outside of the current file.

To Reproduce

lombokeclipse/LombokCheck.java

package lombokeclipse;
public class LombokCheck {
    public static void main(String[] args) {
        new NullCheck().setTheString(null);
    }
}

lombokeclipse/NullCheck.java

package lombokeclipse;
@org.eclipse.jdt.annotation.NonNullByDefault
@lombok.Setter
public class NullCheck {
    private @Nullable String theString;
}

When cleaning the project (full build), everything is fine. Making a non-change to LombokCheck (add or remove a space for example), causes the call to setTheString to produce an error that the value must not be null. It appears that the compiler sees the @NonNullByDefault in NullCheck's source, and it sees the setTheString method just fine, but it does not see the @nullable annotation on the generated method.

Expected behavior
Eclipse performs null analysis correctly during incremental build.

Version info

  • Lombok version: 1.18.22
  • Eclipse (checked versions 2020-06 through 2021-12)

Additional context
Attached an Eclipse project demonstrating the issue (lombok jar not included for size; add your own).
lombok-test.zip

@Rawi01 Rawi01 self-assigned this Mar 12, 2022
@Rawi01 Rawi01 added bug eclipse accepted The issue/enhancement is valid, sensible, and explained in sufficient detail labels Mar 12, 2022
Rawi01 added a commit to Rawi01/lombok that referenced this issue Mar 13, 2022
@jopatai
Copy link
Contributor Author

jopatai commented Mar 14, 2022

This same problem exists with EqualsAndHashCode. I tried adding the appropriate bits to the Equals and CanEquals methods, but was surprised to find it did not seem to fix the issue.

@jopatai
Copy link
Contributor Author

jopatai commented Mar 14, 2022

Figured out the issue on my end and created a PR with additional changes for this.

@rzwitserloot
Copy link
Collaborator

@JohnPaulTaylorII Hmm, @Rawi01 just added a PR a day before yours which seems a bit simpler and is playing in the same space (namely, setting the Eclipse.HasTypeAnnotations flag). Can you check if @Rawi01's patch (commit b50a9c2, currently already in lombok's main branch) fully addresses this issue, and if not (and yours does), let me know?

Reopening for a moment, until this is resolved.

@rzwitserloot rzwitserloot reopened this Mar 15, 2022
@Rawi01
Copy link
Collaborator

Rawi01 commented Mar 15, 2022

My PR only handles copied annotations, the new one is about generated @Nullable/@NonNull annotations. Adding the bits for these annotations makes sense to me.

@jopatai
Copy link
Contributor Author

jopatai commented Mar 15, 2022

@rzwitserloot Sorry for the confusion. I had pulled @Rawi01's changes and realized that it didn't completely fix the bug, so I made a PR with additional changes. The two PRs complement each other and both are necessary to close this issue.

rzwitserloot added a commit that referenced this issue Mar 17, 2022
[fixes #3133] Additional bits setting when creating type annotations
@rzwitserloot rzwitserloot added this to the next-version milestone Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants