From 0082ec4bd21bfba4d78b5cb28e41e6562ee94767 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Tue, 25 Nov 2025 14:00:25 -0800 Subject: [PATCH] Remove null assignability to function arguments for Protobuf messages PiperOrigin-RevId: 836803181 --- runtime/src/main/java/dev/cel/runtime/BUILD.bazel | 2 -- .../src/main/java/dev/cel/runtime/CelResolvedOverload.java | 5 +---- .../java/dev/cel/runtime/CelLateFunctionBindingsTest.java | 7 ++----- .../test/java/dev/cel/runtime/CelResolvedOverloadTest.java | 4 ++-- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/runtime/src/main/java/dev/cel/runtime/BUILD.bazel b/runtime/src/main/java/dev/cel/runtime/BUILD.bazel index 98d6244aa..35d5358e9 100644 --- a/runtime/src/main/java/dev/cel/runtime/BUILD.bazel +++ b/runtime/src/main/java/dev/cel/runtime/BUILD.bazel @@ -1174,7 +1174,6 @@ java_library( "//:auto_value", "@maven//:com_google_errorprone_error_prone_annotations", "@maven//:com_google_guava_guava", - "@maven//:com_google_protobuf_protobuf_java", ], ) @@ -1189,7 +1188,6 @@ cel_android_library( "//:auto_value", "@maven//:com_google_errorprone_error_prone_annotations", "@maven_android//:com_google_guava_guava", - "@maven_android//:com_google_protobuf_protobuf_javalite", ], ) diff --git a/runtime/src/main/java/dev/cel/runtime/CelResolvedOverload.java b/runtime/src/main/java/dev/cel/runtime/CelResolvedOverload.java index 74d9e269e..f7cd9f2c0 100644 --- a/runtime/src/main/java/dev/cel/runtime/CelResolvedOverload.java +++ b/runtime/src/main/java/dev/cel/runtime/CelResolvedOverload.java @@ -17,7 +17,6 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.Immutable; -import com.google.protobuf.MessageLite; import java.util.List; import java.util.Map; @@ -89,9 +88,7 @@ boolean canHandle(Object[] arguments) { if (arg == null) { // null can be assigned to messages, maps, and to objects. // TODO: Remove null special casing - if (paramType != Object.class - && !MessageLite.class.isAssignableFrom(paramType) - && !Map.class.isAssignableFrom(paramType)) { + if (paramType != Object.class && !Map.class.isAssignableFrom(paramType)) { return false; } continue; diff --git a/runtime/src/test/java/dev/cel/runtime/CelLateFunctionBindingsTest.java b/runtime/src/test/java/dev/cel/runtime/CelLateFunctionBindingsTest.java index 395fb0897..819b99665 100644 --- a/runtime/src/test/java/dev/cel/runtime/CelLateFunctionBindingsTest.java +++ b/runtime/src/test/java/dev/cel/runtime/CelLateFunctionBindingsTest.java @@ -130,16 +130,13 @@ public void findOverload_nullPrimitiveArg_isEmpty() throws Exception { } @Test - public void findOverload_nullMessageArg_returnsOverload() throws Exception { + public void findOverload_nullMessageArg_isEmpty() throws Exception { CelLateFunctionBindings bindings = CelLateFunctionBindings.from( CelFunctionBinding.from("identity_msg", TestAllTypes.class, (arg) -> arg)); Optional overload = bindings.findOverloadMatchingArgs( "identity", ImmutableList.of("identity_msg"), new Object[] {null}); - assertThat(overload).isPresent(); - assertThat(overload.get().getOverloadId()).isEqualTo("identity_msg"); - assertThat(overload.get().getParameterTypes()).containsExactly(TestAllTypes.class); - assertThat(overload.get().getDefinition().apply(new Object[] {null})).isNull(); + assertThat(overload).isEmpty(); } } diff --git a/runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java b/runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java index 40e2075aa..c1210c1ba 100644 --- a/runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java +++ b/runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java @@ -42,11 +42,11 @@ public void canHandle_matchingTypes_returnsTrue() { } @Test - public void canHandle_nullMessageType_returnsTrue() { + public void canHandle_nullMessageType_returnsFalse() { CelResolvedOverload overload = CelResolvedOverload.of( "identity", (args) -> args[0], /* isStrict= */ true, TestAllTypes.class); - assertThat(overload.canHandle(new Object[] {null})).isTrue(); + assertThat(overload.canHandle(new Object[] {null})).isFalse(); } @Test