peichhorn / lombok-pg

Collection of lombok extensions
http://peichhorn.github.com/lombok-pg/
Other
326 stars 44 forks source link

Builder should respect @NonNull annotation. #129

Open patientstreetlight opened 11 years ago

patientstreetlight commented 11 years ago

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, https://github.com/peichhorn/lombok-pg/issues/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 commented 11 years ago

If you could provide a fix, I will merge