Skip to content

Commit a72036d

Browse files
l46kokcopybara-github
authored andcommitted
Return zero values for missing wrapper map values in the lite runtime
PiperOrigin-RevId: 995526692
1 parent fa4a240 commit a72036d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎common/src/main/java/dev/cel/common/values/ProtoLiteCelValueConverter.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ private Map.Entry<Object, Object> readSingleMapEntry(
311311
key = getDefaultCelValue(keyDescriptor);
312312
}
313313
if (value == null) {
314-
value = getDefaultCelValue(valueDescriptor);
314+
// Map values have no presence, so a missing message (even a wrapper) is empty, not null.
315+
value =
316+
valueDescriptor.getJavaType().equals(JavaType.MESSAGE)
317+
? readMessageField(ByteString.EMPTY, valueDescriptor.getFieldProtoTypeName())
318+
: getDefaultCelValue(valueDescriptor);
315319
}
316320

317321
return new AbstractMap.SimpleImmutableEntry<>(key, value);

‎common/src/test/java/dev/cel/common/values/ProtoLiteCelValueConverterTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ private enum ReadSingleFieldTestCase {
587587
REPEATED_INT32(TestAllTypes.REPEATED_INT32_FIELD_NUMBER, ImmutableList.of(1L, 2L)),
588588
MAP_STRING_STRING(
589589
TestAllTypes.MAP_STRING_STRING_FIELD_NUMBER, ImmutableMap.of("k", "v", "k2", "v2", "", "")),
590+
MAP_STRING_INT64_WRAPPER(
591+
TestAllTypes.MAP_STRING_INT64_WRAPPER_FIELD_NUMBER, ImmutableMap.of("", 0L)),
590592
SPLIT_DURATION(
591593
TestAllTypes.SINGLE_DURATION_FIELD_NUMBER, java.time.Duration.ofSeconds(10, 500));
592594

@@ -630,6 +632,8 @@ public void readSingleField_skipsOtherFieldsAndDecodesTarget(
630632
extraWireCos.writeByteArray(TestAllTypes.REPEATED_INT32_FIELD_NUMBER, new byte[0]);
631633
extraWireCos.writeByteArray(
632634
TestAllTypes.MAP_STRING_STRING_FIELD_NUMBER, mapEntryWithUnknownOut.toByteArray());
635+
extraWireCos.writeByteArray(
636+
TestAllTypes.MAP_STRING_INT64_WRAPPER_FIELD_NUMBER, mapEntryWithUnknownOut.toByteArray());
633637
extraWireCos.flush();
634638
ByteString bytes =
635639
part1

0 commit comments

Comments
 (0)