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

Builder should respect @NonNull annotation. #129

Open
patientstreetlight opened this issue Oct 25, 2012 · 1 comment
Open

Builder should respect @NonNull annotation. #129

patientstreetlight opened this issue Oct 25, 2012 · 1 comment

Comments

@patientstreetlight
Copy link

In the version of lombok-pg I'm using (0.11.3), Builder will allow fields which are marked @NonNull to be initialized to null, as demonstrated below. If possible, I think Builder should do a runtime check to ensure that the object passed in is indeed not null, just like @Setter does.

import lombok.Builder;
import lombok.NonNull;
import lombok.Getter;

@Builder
@Getter
class Foo {
    @NonNull private final String bar;

    public static void main(String[] args){
        Foo f = Foo.foo().bar(null).build();  // Does *not* throw NullPointerException
        System.out.println(f.getBar()); // Prints null.
    }
}

I am aware of a similar-sounding issue, #54. However that issue seems to indicate that fields marked @NonNull should be mandatory fields (just like final fields), but does not mention that the Builder should actually do the null check.

@nicholas22
Copy link
Collaborator

If you could provide a fix, I will merge

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