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

[FEATURE] Support Jakarta Nonnull/Nullable annotations #3346

Closed
jvwilge opened this issue Feb 8, 2023 · 3 comments · Fixed by #3350
Closed

[FEATURE] Support Jakarta Nonnull/Nullable annotations #3346

jvwilge opened this issue Feb 8, 2023 · 3 comments · Fixed by #3350
Assignees
Milestone

Comments

@jvwilge
Copy link

jvwilge commented Feb 8, 2023

I ran into an issue with using Jakarta's @Nullable instead of javax (or checker).

I tried to add the config property :

lombok.addNullAnnotations = CUSTOM:jakarta.annotation.Nonnull:jakarta.annotation.Nullable

And it seems to partially work (e.g. for return values), but when using @Builder the @Nullable is not copied to the parameter of the generated method first() on the Builder.

import jakarta.annotation.Nullable;
import java.util.List;
import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class JakartaExample {

    @Nullable
    List<String> first;

}

I'd expect

public JakartaExample.JakartaExampleBuilder first(@Nullable final List<String> first) {
      this.first = first;
      return this;
}

as a builder method, but currently the @Nullable is not copied (it does work for javax and checkerframework as expected)

Not sure if it's important, but if I use the javax or checker annotations the @Nullable is copied, even when lombok.addNullAnnotations has the custom value mentioned above. So it seems some annotations are copied by default, regardless of the value of lombok.addNullAnnotations

@Rawi01
Copy link
Collaborator

Rawi01 commented Feb 8, 2023

You mixed up two different thinks. lombok.addNullAnnotations set the annotations that get used for generated code. If you want to copy annotations that are not in the internal base list you have to use lombok.copyableAnnotations.

Apart from that, I agree that Jakarta annotations should be directly supported.

@Rawi01 Rawi01 self-assigned this Feb 8, 2023
@jvwilge
Copy link
Author

jvwilge commented Feb 9, 2023

That config property will solve my issue, thanks for your swift reply! But it would be nice if this is an automatic one since many frameworks (spring-boot 3 for example) switched to Jakarta.

I don't want to be a smart*ss, but technically the builder code is generated code, the sample I posted was generated by delombok (and I added @Nullable myself).

I read something about the copyableAnnotations in an issue , but couldn't find it in https://projectlombok.org/features/configuration
Shouldn't this property be there?

So for other people running into this issue, add this to your config:

lombok.copyableAnnotations+=jakarta.annotation.Nonnull
lombok.copyableAnnotations+=jakarta.annotation.Nullable

@rzwitserloot
Copy link
Collaborator

Available on edge.

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

Successfully merging a pull request may close this issue.

3 participants