Thanks for putting together record-builder! It's definitely a welcome addition and enhancement on top of records.
Issue/Enhancement
Some codebases expect fields to be non-null by default, for example if NullAway enforcement is in place. Therefore it is useful to set a parameter to expect that all fields will be non-null unless explicitly marked as nullable.
Currently our codebase uses https://immutables.github.io/immutable.html which defaults to non-null fields, and it would be good to have record-builder have the capability for the same behaviour.
Changes
Adds the ability to default fields to be non-null, unless they are annoted with a nullable annotation, ie:
@RecordBuilder.Options(defaultNotNull = true)
@RecordBuilder
public record RecordWithDefaultNotNull(Integer notNullInteger, String notNullString, @Null String nullString) {
}
will check/ensure that notNullInteger and notNullString are not null via requireNonNull calls.
Questions
What happens for collections? Can we enforce non-nullability in the same way by defaulting to non-null? Or is this not required because collections are non-null by default anyway.
Can we also support other annotations such as javax.annotation.ParametersAreNonnullByDefault? That might be a future enhancement.
Thanks for putting together record-builder! It's definitely a welcome addition and enhancement on top of
record
s.Issue/Enhancement
Some codebases expect fields to be non-null by default, for example if NullAway enforcement is in place. Therefore it is useful to set a parameter to expect that all fields will be non-null unless explicitly marked as nullable. Currently our codebase uses https://immutables.github.io/immutable.html which defaults to non-null fields, and it would be good to have record-builder have the capability for the same behaviour.
Changes
Adds the ability to default fields to be non-null, unless they are annoted with a nullable annotation, ie:
Example
For example:
will check/ensure that
notNullInteger
andnotNullString
are not null viarequireNonNull
calls.Questions
javax.annotation.ParametersAreNonnullByDefault
? That might be a future enhancement.