Commit 92f39e0
Fix unnecessary required field checking on serialize of message-typed map fields.
On map fields the Serialize and SerializedLength create temporary instances of synthetic map entries and .build() on them: this change switches it to instead use buildPartial() in these cases.
This is a semantics observable change in a corner case, but in a bugfix direction: JavaProto's normal semantics is to only check required fields at .build() time, which allows for buildPartial() and then serialize if you want to intentionally serialize with required fields missing or as a microoptimization skip checking for required fields being set.
Only in the case of message-typed-values of map fields serialize may fail with missing required fields: it will happen if the user does buildPartial(), sets it on a map, and then serializes, since the build() on the synthetic map entry will recheck for required fields. After this change the behavior on that shape of flow is consistent with our standard serialize.
PiperOrigin-RevId: 8494852211 parent 93b5196 commit 92f39e0
File tree
2 files changed
+2
-2
lines changed- java/core/src/main/java/com/google/protobuf
- src/google/protobuf/compiler/java/full
2 files changed
+2
-2
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3511 | 3511 | | |
3512 | 3512 | | |
3513 | 3513 | | |
3514 | | - | |
| 3514 | + | |
3515 | 3515 | | |
3516 | 3516 | | |
3517 | 3517 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1043 | 1043 | | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | | - | |
| 1046 | + | |
1047 | 1047 | | |
1048 | 1048 | | |
1049 | 1049 | | |
| |||
0 commit comments