diff options
author | Éamonn McManus <emcmanus@google.com> | 2022-10-25 11:46:05 -0700 |
---|---|---|
committer | Google Java Core Libraries <java-libraries-firehose+copybara@google.com> | 2022-10-25 11:47:10 -0700 |
commit | 3659a0e6436d3acfeda04e0bd1df3603f1e7ffac (patch) | |
tree | fd3d809f180ebdd2c3cccb805a30bec7aaa2c486 /value/src/main/java/com | |
parent | aeffb9065d90af9e2cb67c0ecd6de10a926e0462 (diff) | |
download | auto-3659a0e6436d3acfeda04e0bd1df3603f1e7ffac.tar.gz |
Fix an issue with builder getters.
In a builder, if a property `bar` has its own builder `barBuilder()` and also a getter `bar()`, then either the property must be set or `barBuilder()` must be called.
If neither of those has happened, both the `bar` and `barBuilder$` fields will be null, and we should correctly report that with an empty `Optional` return from `bar()`.
Previously we incorrectly simplified this logic and ended up calling `Optional.of(bar)` even though `bar` is null.
Fixes https://github.com/google/auto/issues/1386. Thanks to @jmesny for the bug report and regression test.
RELNOTES=Fixed an issue when a builder has a property `foo` with both a getter `foo()` and a builder `fooBuilder()`.
PiperOrigin-RevId: 483736037
Diffstat (limited to 'value/src/main/java/com')
-rw-r--r-- | value/src/main/java/com/google/auto/value/processor/builder.vm | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/value/src/main/java/com/google/auto/value/processor/builder.vm b/value/src/main/java/com/google/auto/value/processor/builder.vm index 5c4f4d5d..d032cda9 100644 --- a/value/src/main/java/com/google/auto/value/processor/builder.vm +++ b/value/src/main/java/com/google/auto/value/processor/builder.vm @@ -192,7 +192,7 @@ class ${builderName}${builderFormalTypes} ## if ($noValueToGetCondition) { return $builderGetter.optional.empty; } - #elseif ($p.nullable) + #else if ($p == null) { return $builderGetter.optional.empty; } |