From ed05bdd0afdd10a7760ec61db9a9d8502318cc1c Mon Sep 17 00:00:00 2001 From: Sean Huh Date: Tue, 24 Nov 2026 17:45:45 -0800 Subject: [PATCH] Reject evaluateCanonicalTypesToNativeValues(false) in the planner and lite runtimes PiperOrigin-RevId: 1029472944 --- PLANNER_MIGRATION_GUIDE.md | 1 + .../test/java/dev/cel/bundle/CelImplTest.java | 16 ++++++++++++++++ .../java/dev/cel/runtime/CelLiteRuntimeImpl.java | 4 ++++ .../java/dev/cel/runtime/CelRuntimeImpl.java | 4 ++++ .../cel/runtime/CelLiteRuntimeAndroidTest.java | 3 +++ 5 files changed, 28 insertions(+) diff --git a/PLANNER_MIGRATION_GUIDE.md b/PLANNER_MIGRATION_GUIDE.md index b0f5ba7aa..8c30cdddc 100644 --- a/PLANNER_MIGRATION_GUIDE.md +++ b/PLANNER_MIGRATION_GUIDE.md @@ -51,6 +51,7 @@ CelOptions options = CelOptions.current() // .unwrapWellKnownTypesOnFunctionDispatch(...) // .enableTimestampEpoch(...) // .enableHeterogeneousNumericComparisons(...) + // .evaluateCanonicalTypesToNativeValues(...) .build(); CelRuntime runtime = CelRuntimeFactory.plannerRuntimeBuilder() diff --git a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java index f5ac998bc..c7f2874ed 100644 --- a/bundle/src/test/java/dev/cel/bundle/CelImplTest.java +++ b/bundle/src/test/java/dev/cel/bundle/CelImplTest.java @@ -1893,6 +1893,22 @@ public void program_regexProgramSizeExceedsLimit_throws() throws Exception { assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.INVALID_ARGUMENT); } + @Test + @SuppressWarnings("deprecation") // Test only - verifying the deprecated option is rejected + public void planner_evaluateCanonicalTypesToNativeValuesDisabled_throws() { + CelRuntimeBuilder runtimeBuilder = + CelRuntimeFactory.plannerRuntimeBuilder() + .setOptions(CelOptions.current().evaluateCanonicalTypesToNativeValues(false).build()); + + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, runtimeBuilder::build); + + assertThat(e) + .hasMessageThat() + .isEqualTo( + "Misconfigured CelOptions: evaluateCanonicalTypesToNativeValues cannot be disabled."); + } + @Test @SuppressWarnings("unchecked") // test only public void program_evaluateCanonicalTypesToNativeTypesDisabled_producesProtoValues() diff --git a/runtime/src/main/java/dev/cel/runtime/CelLiteRuntimeImpl.java b/runtime/src/main/java/dev/cel/runtime/CelLiteRuntimeImpl.java index 87e3e40cc..e41e39975 100644 --- a/runtime/src/main/java/dev/cel/runtime/CelLiteRuntimeImpl.java +++ b/runtime/src/main/java/dev/cel/runtime/CelLiteRuntimeImpl.java @@ -170,6 +170,10 @@ private static void assertAllowedCelOptions(CelOptions celOptions) { throw new IllegalArgumentException( prefix + "unwrapWellKnownTypesOnFunctionDispatch cannot be disabled."); } + if (!celOptions.evaluateCanonicalTypesToNativeValues()) { + throw new IllegalArgumentException( + prefix + "evaluateCanonicalTypesToNativeValues cannot be disabled."); + } } private static void addBindingToDispatcher( diff --git a/runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java b/runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java index 987e3c265..7a9d2506b 100644 --- a/runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java +++ b/runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java @@ -452,6 +452,10 @@ private static void assertAllowedCelOptions(CelOptions celOptions) { + "enableTimestampEpoch cannot be disabled. Subset the environment instead using" + " setStandardFunctions method."); } + if (!celOptions.evaluateCanonicalTypesToNativeValues()) { + throw new IllegalArgumentException( + prefix + "evaluateCanonicalTypesToNativeValues cannot be disabled."); + } } abstract CelRuntimeImpl autoBuild(); diff --git a/runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java b/runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java index f4d5da19b..2820607ec 100644 --- a/runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java +++ b/runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java @@ -919,6 +919,9 @@ public void eval_messageCreation_returnsMessageLite() throws Exception { private enum CelOptionsTestCase { UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()), UNWRAP_WKT_DISABLED(newBaseTestOptions().unwrapWellKnownTypesOnFunctionDispatch(false).build()), + @SuppressWarnings("deprecation") // Test only - verifying the deprecated option is rejected + NATIVE_VALUES_DISABLED( + newBaseTestOptions().evaluateCanonicalTypesToNativeValues(false).build()), ; private final CelOptions celOptions;