palantir / conjure-java

Conjure generator for Java clients and servers
Apache License 2.0
27 stars 43 forks source link

Add @CheckReturnValue onto generated conjure object methods #2281

Closed ash211 closed 7 months ago

ash211 commented 7 months ago

What happened?

A product I maintain recently had a bug where we instantiated a conjure object in Java source and then did nothing with it. ErrorProne has a @CheckReturnValue pattern meant to help with this. Let's apply it and try to squash this category of bug entirely.

What did you want to happen?

Add @CheckReturnValue to the generated MyObject.builder() and MyObject.Builder.build() methods. When paired with the error prone rule, this will catch any issues where callers call one of those methods but then discard the result. This will manifest as a build failure when they pick up the new version of conjure-java.