Final stage builder methods' return value should be ignorable #1568
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change-set should annotate final stage builder interfaces (
BuildFinal
) with CanIgnoreReturnValue, and allow downstream projects using Error Prone to use Staged Builders without method chaining or disabling the CheckReturnValue bug-checker. This aligns with the existing implementation and "normal" and strict builders.Aside from this change, I have a broader question:
We encountered this while trying to propagate optional values to default primitive members in our immutable models. For example, the following model
Foo
will produce a single builder method forFoo#bar
,BuildFinal bar(int bar)
, which cannot be called with anOptional<Integer>
with method chaining, only conditionally with the optional unwrapped.Have you considered generating "optional" builder methods for default non-optional members? In this example,
BuildFinal bar(Optional<Integer> bar)
?I've managed to implement this for object types, but not for primitives. I didn't yet find a way to map primitives to their boxed optional types.
If this feature would be welcome, I may give it a go, and ask for you input, pointers on it.
Thanks all!