From c368450ce7bb0291cf2bfbfc466878d62db4f964 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Mon, 21 Jul 2025 00:45:36 -0700 Subject: [PATCH] Remove dead code in interpreter util PiperOrigin-RevId: 785326726 --- .../dev/cel/runtime/DefaultInterpreter.java | 5 +-- .../java/dev/cel/runtime/InterpreterUtil.java | 39 ++----------------- 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java b/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java index d0a987261..f029b2d3b 100644 --- a/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java +++ b/runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java @@ -585,9 +585,8 @@ private IntermediateResult mergeBooleanUnknowns(IntermediateResult lhs, Intermed return rhs; } - // Otherwise fallback to normal impl - return IntermediateResult.create( - InterpreterUtil.shortcircuitUnknownOrThrowable(lhsVal, rhsVal)); + // Otherwise, enforce strictness on both args + return IntermediateResult.create(InterpreterUtil.enforceStrictness(lhsVal, rhsVal)); } private enum ShortCircuitableOperators { diff --git a/runtime/src/main/java/dev/cel/runtime/InterpreterUtil.java b/runtime/src/main/java/dev/cel/runtime/InterpreterUtil.java index 20ce6e9f2..f84897ac2 100644 --- a/runtime/src/main/java/dev/cel/runtime/InterpreterUtil.java +++ b/runtime/src/main/java/dev/cel/runtime/InterpreterUtil.java @@ -16,8 +16,6 @@ import com.google.errorprone.annotations.CheckReturnValue; import dev.cel.common.annotations.Internal; -import java.util.LinkedHashSet; -import java.util.Set; import org.jspecify.annotations.Nullable; /** @@ -74,42 +72,11 @@ static AccumulatedUnknowns adaptToAccumulatedUnknowns(CelUnknownSet unknowns) { return AccumulatedUnknowns.create(unknowns.unknownExprIds(), unknowns.attributes()); } - static AccumulatedUnknowns combineUnknownExprValue(Object... objs) { - Set ids = new LinkedHashSet<>(); - for (Object object : objs) { - if (isAccumulatedUnknowns(object)) { - ids.addAll(((AccumulatedUnknowns) object).exprIds()); - } - } - - return AccumulatedUnknowns.create(ids); - } - /** - * Short circuit unknown or error arguments to logical operators. - * - *

Given two arguments, one of which must be throwable (error) or unknown, returns the result - * from the && or || operators for these arguments, assuming that the result cannot be determined - * from any boolean arguments alone. This allows us to consolidate the error/unknown handling for - * both of these operators. + * Enforces strictness on both lhs/rhs arguments from logical operators (i.e: intentionally throws + * an appropriate exception when {@link Throwable} is encountered as part of evaluated result. */ - public static Object shortcircuitUnknownOrThrowable(Object left, Object right) - throws CelEvaluationException { - // unknown unknown ==> unknown combined - if (InterpreterUtil.isAccumulatedUnknowns(left) - && InterpreterUtil.isAccumulatedUnknowns(right)) { - return InterpreterUtil.combineUnknownExprValue(left, right); - } - // unknown ==> unknown - // unknown t|f ==> unknown - if (InterpreterUtil.isAccumulatedUnknowns(left)) { - return left; - } - // unknown ==> unknown - // t|f unknown ==> unknown - if (InterpreterUtil.isAccumulatedUnknowns(right)) { - return right; - } + public static Object enforceStrictness(Object left, Object right) throws CelEvaluationException { // Throw left or right side exception for now, should combine them into ErrorSet. // ==> if (left instanceof Throwable) {