Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
756 stars 55 forks source link

Builder defaults for collections are inconsistent with output record #122

Open fprochazka opened 2 years ago

fprochazka commented 2 years ago

Hi, awesome library! Love it! I just have a small suggestion...

If I have a record with any collection

@MyRecordBuilder // with useImmutableCollections = true, interpretNotNulls = true
public record Costs(
    @Nullable BigDecimal shipping,
    Map<String, Object> extraData
) { }

I'm proposing that since you're adding special handling of collections and always initializing them, they should also be initialized to empty collections when the empty builder is created, so that the second case will also not throw an NPE

Randgalt commented 2 years ago

Could these be combined into a single PR? Maybe with a new option to avoid breaking existing code.

fprochazka commented 2 years ago

@Randgalt I've created two issues because I expected others to have a different opinion and you might be willing to accept only one part of the proposal, but both of the issues are related in my mind.

hofiisek commented 1 year ago

Isn't this one solved by this?