Hello. I have immutable bean with lots of fields and builder for it:
@NullMarked
public class A {
private final String hello;
private final @Nullable Integer world;
public static Builder newBuilder() {
return new Builder();
}
public A(String hello, @Nullable Integer world) {
this.hello = Objects.requireNonNull(hello);
this.world = world;
}
public String getHello() {
return hello;
}
public @Nullable Integer getWorld() {
return world;
}
public static class Builder {
private String hello;
private @Nullable Integer world;
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public @Nullable Integer getWorld() {
return world;
}
public void setWorld(@Nullable Integer world) {
this.world = world;
}
public A build() {
return new A(hello, world);
}
}
}
IDE claims about hello field in builder (and CI system stops the build):
I can't initialize this field, because there's no suitable default value according to business logic of my object (even empty string). I can't mark this field as nullable, because this defeats main purpose of jspecify - take guidance for developer which fields are optional and which not.
It's ok that hello field takes null. Later it will be set by developer.
How to deal with this situation?