Skip to content

Commit 0082ec4

Browse files
l46kokcopybara-github
authored andcommitted
Remove null assignability to function arguments for Protobuf messages
PiperOrigin-RevId: 836803181
1 parent aa9f794 commit 0082ec4

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

runtime/src/main/java/dev/cel/runtime/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,6 @@ java_library(
11741174
"//:auto_value",
11751175
"@maven//:com_google_errorprone_error_prone_annotations",
11761176
"@maven//:com_google_guava_guava",
1177-
"@maven//:com_google_protobuf_protobuf_java",
11781177
],
11791178
)
11801179

@@ -1189,7 +1188,6 @@ cel_android_library(
11891188
"//:auto_value",
11901189
"@maven//:com_google_errorprone_error_prone_annotations",
11911190
"@maven_android//:com_google_guava_guava",
1192-
"@maven_android//:com_google_protobuf_protobuf_javalite",
11931191
],
11941192
)
11951193

runtime/src/main/java/dev/cel/runtime/CelResolvedOverload.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.errorprone.annotations.Immutable;
20-
import com.google.protobuf.MessageLite;
2120
import java.util.List;
2221
import java.util.Map;
2322

@@ -89,9 +88,7 @@ boolean canHandle(Object[] arguments) {
8988
if (arg == null) {
9089
// null can be assigned to messages, maps, and to objects.
9190
// TODO: Remove null special casing
92-
if (paramType != Object.class
93-
&& !MessageLite.class.isAssignableFrom(paramType)
94-
&& !Map.class.isAssignableFrom(paramType)) {
91+
if (paramType != Object.class && !Map.class.isAssignableFrom(paramType)) {
9592
return false;
9693
}
9794
continue;

runtime/src/test/java/dev/cel/runtime/CelLateFunctionBindingsTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,13 @@ public void findOverload_nullPrimitiveArg_isEmpty() throws Exception {
130130
}
131131

132132
@Test
133-
public void findOverload_nullMessageArg_returnsOverload() throws Exception {
133+
public void findOverload_nullMessageArg_isEmpty() throws Exception {
134134
CelLateFunctionBindings bindings =
135135
CelLateFunctionBindings.from(
136136
CelFunctionBinding.from("identity_msg", TestAllTypes.class, (arg) -> arg));
137137
Optional<CelResolvedOverload> overload =
138138
bindings.findOverloadMatchingArgs(
139139
"identity", ImmutableList.of("identity_msg"), new Object[] {null});
140-
assertThat(overload).isPresent();
141-
assertThat(overload.get().getOverloadId()).isEqualTo("identity_msg");
142-
assertThat(overload.get().getParameterTypes()).containsExactly(TestAllTypes.class);
143-
assertThat(overload.get().getDefinition().apply(new Object[] {null})).isNull();
140+
assertThat(overload).isEmpty();
144141
}
145142
}

runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public void canHandle_matchingTypes_returnsTrue() {
4242
}
4343

4444
@Test
45-
public void canHandle_nullMessageType_returnsTrue() {
45+
public void canHandle_nullMessageType_returnsFalse() {
4646
CelResolvedOverload overload =
4747
CelResolvedOverload.of(
4848
"identity", (args) -> args[0], /* isStrict= */ true, TestAllTypes.class);
49-
assertThat(overload.canHandle(new Object[] {null})).isTrue();
49+
assertThat(overload.canHandle(new Object[] {null})).isFalse();
5050
}
5151

5252
@Test

0 commit comments

Comments
 (0)