Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make @Builder work with both Default and throwing constructor #2878

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

emlun
Copy link
Contributor

@emlun emlun commented Jun 16, 2021

Currently, if the constructor throws a checked exception then @Builder must be on the constructor in order for the checked exception to propagate to the throws clause of the builder() method. However, @Builder.Default requires that the @Builder annotation be set on the class. It is possible to annotate both the class and the constructor, but then the constructor one gets skipped. This means it is currently impossible to use @Builder.Default simultaneously with a throwing constructor (except perhaps by manually implementing the builder() method), as demonstrated by the tests added in commit d905be5.

This attempts to fix that. If you set @Builder on both the class and the constructor, the constructor's checked exceptions will now be added to the builder() method initially generated by the class annotation. I have also verified that this works in the real-world context where I encountered the issue.

@emlun
Copy link
Contributor Author

emlun commented Jun 16, 2021

Oh, and I'm basing the branch on v1.18.20 because I couldn't get the tests to pass on any later commits. I hope that doesn't cause any trouble, I'm happy to fix the merge conflicts once that becomes relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant