Skip to content

Commit c3dcc7e

Browse files
l46kokcopybara-github
authored andcommitted
Drop support for java.lang.long uint support in CelValue
PiperOrigin-RevId: 750824161
1 parent 2062875 commit c3dcc7e

File tree

8 files changed

+23
-29
lines changed

8 files changed

+23
-29
lines changed

common/src/main/java/dev/cel/common/values/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ java_library(
149149
":cel_value_provider",
150150
":proto_message_value",
151151
"//common:error_codes",
152-
"//common:options",
153152
"//common:runtime_exception",
154153
"//common/annotations",
155154
"//common/internal:dynamic_proto",

common/src/main/java/dev/cel/common/values/BaseProtoCelValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ protected CelValue fromWellKnownProtoToCelValue(
127127
case STRING_VALUE:
128128
return fromJavaPrimitiveToCelValue(((StringValue) message).getValue());
129129
case UINT32_VALUE:
130-
return UintValue.create(((UInt32Value) message).getValue(), true);
130+
return UintValue.create(((UInt32Value) message).getValue());
131131
case UINT64_VALUE:
132-
return UintValue.create(((UInt64Value) message).getValue(), true);
132+
return UintValue.create(((UInt64Value) message).getValue());
133133
default:
134134
throw new UnsupportedOperationException(
135135
"Unsupported message to CelValue conversion - " + message);

common/src/main/java/dev/cel/common/values/CelValueConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected CelValue fromJavaPrimitiveToCelValue(Object value) {
109109
} else if (value instanceof Float) {
110110
return DoubleValue.create(Double.valueOf((Float) value));
111111
} else if (value instanceof UnsignedLong) {
112-
return UintValue.create(((UnsignedLong) value).longValue(), /* enableUnsignedLongs= */ true);
112+
return UintValue.create((UnsignedLong) value);
113113
}
114114

115115
// Fall back to an Opaque value, as a custom class was supplied in the runtime. The legacy

common/src/main/java/dev/cel/common/values/ProtoCelValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ public CelValue fromProtoMessageFieldToCelValue(
153153

154154
return fromProtoMessageToCelValue((MessageOrBuilder) result);
155155
case UINT32:
156-
return UintValue.create((int) result, true);
156+
return UintValue.create((int) result);
157157
case UINT64:
158-
return UintValue.create((long) result, true);
158+
return UintValue.create((long) result);
159159
default:
160160
break;
161161
}

common/src/main/java/dev/cel/common/values/ProtoMessageValueProvider.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.protobuf.Descriptors.FieldDescriptor;
2020
import com.google.protobuf.Message;
2121
import dev.cel.common.CelErrorCode;
22-
import dev.cel.common.CelOptions;
2322
import dev.cel.common.CelRuntimeException;
2423
import dev.cel.common.annotations.Internal;
2524
import dev.cel.common.internal.DynamicProto;
@@ -92,15 +91,14 @@ private FieldDescriptor findField(Descriptor descriptor, String fieldName) {
9291
fieldName, descriptor.getFullName())));
9392
}
9493

95-
public static ProtoMessageValueProvider newInstance(
96-
DynamicProto dynamicProto, CelOptions celOptions) {
97-
return new ProtoMessageValueProvider(dynamicProto, celOptions);
94+
public static ProtoMessageValueProvider newInstance(DynamicProto dynamicProto) {
95+
return new ProtoMessageValueProvider(dynamicProto);
9896
}
9997

100-
private ProtoMessageValueProvider(DynamicProto dynamicProto, CelOptions celOptions) {
98+
private ProtoMessageValueProvider(DynamicProto dynamicProto) {
10199
this.protoMessageFactory = dynamicProto.getProtoMessageFactory();
102100
this.protoCelValueConverter =
103101
ProtoCelValueConverter.newInstance(protoMessageFactory.getDescriptorPool(), dynamicProto);
104-
this.protoAdapter = new ProtoAdapter(dynamicProto, celOptions.enableUnsignedLongs());
102+
this.protoAdapter = new ProtoAdapter(dynamicProto, true);
105103
}
106104
}

common/src/main/java/dev/cel/common/values/UintValue.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
@Immutable
2828
@AutoValue
2929
@AutoValue.CopyAnnotations
30-
@SuppressWarnings("Immutable") // value is either a boxed long or an immutable UnsignedLong.
3130
public abstract class UintValue extends CelValue {
3231

3332
@Override
34-
public abstract Number value();
33+
public abstract UnsignedLong value();
3534

3635
@Override
3736
public boolean isZeroValue() {
@@ -47,8 +46,7 @@ public static UintValue create(UnsignedLong value) {
4746
return new AutoValue_UintValue(value);
4847
}
4948

50-
public static UintValue create(long value, boolean enableUnsignedLongs) {
51-
Number unsignedLong = enableUnsignedLongs ? UnsignedLong.fromLongBits(value) : value;
52-
return new AutoValue_UintValue(unsignedLong);
49+
public static UintValue create(long value) {
50+
return new AutoValue_UintValue(UnsignedLong.fromLongBits(value));
5351
}
5452
}

common/src/test/java/dev/cel/common/values/ProtoMessageValueProviderTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.protobuf.util.Timestamps;
2525
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2626
import dev.cel.common.CelDescriptorUtil;
27-
import dev.cel.common.CelOptions;
2827
import dev.cel.common.CelRuntimeException;
2928
import dev.cel.common.internal.CelDescriptorPool;
3029
import dev.cel.common.internal.DefaultDescriptorPool;
@@ -56,7 +55,7 @@ public class ProtoMessageValueProviderTest {
5655
@Test
5756
public void newValue_createEmptyProtoMessage() {
5857
ProtoMessageValueProvider protoMessageValueProvider =
59-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
58+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
6059

6160
ProtoMessageValue protoMessageValue =
6261
(ProtoMessageValue)
@@ -70,7 +69,7 @@ public void newValue_createEmptyProtoMessage() {
7069
@Test
7170
public void newValue_createProtoMessage_fieldsPopulated() {
7271
ProtoMessageValueProvider protoMessageValueProvider =
73-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
72+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
7473

7574
ProtoMessageValue protoMessageValue =
7675
(ProtoMessageValue)
@@ -104,9 +103,9 @@ public void newValue_createProtoMessage_fieldsPopulated() {
104103
assertThat(protoMessageValue.select(StringValue.create("single_int64")))
105104
.isEqualTo(IntValue.create(2L));
106105
assertThat(protoMessageValue.select(StringValue.create("single_uint32")))
107-
.isEqualTo(UintValue.create(3L, true));
106+
.isEqualTo(UintValue.create(3L));
108107
assertThat(protoMessageValue.select(StringValue.create("single_uint64")))
109-
.isEqualTo(UintValue.create(4L, true));
108+
.isEqualTo(UintValue.create(4L));
110109
assertThat(protoMessageValue.select(StringValue.create("single_double")))
111110
.isEqualTo(DoubleValue.create(5.5d));
112111
assertThat(protoMessageValue.select(StringValue.create("single_bool")))
@@ -122,7 +121,7 @@ public void newValue_createProtoMessage_fieldsPopulated() {
122121
@Test
123122
public void newValue_createProtoMessage_unsignedLongFieldsPopulated() {
124123
ProtoMessageValueProvider protoMessageValueProvider =
125-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.current().build());
124+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
126125

127126
ProtoMessageValue protoMessageValue =
128127
(ProtoMessageValue)
@@ -143,7 +142,7 @@ public void newValue_createProtoMessage_unsignedLongFieldsPopulated() {
143142
@Test
144143
public void newValue_createProtoMessage_wrappersPopulated() {
145144
ProtoMessageValueProvider protoMessageValueProvider =
146-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
145+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
147146

148147
ProtoMessageValue protoMessageValue =
149148
(ProtoMessageValue)
@@ -189,7 +188,7 @@ public void newValue_createProtoMessage_wrappersPopulated() {
189188
@Test
190189
public void newValue_createProtoMessage_extensionFieldsPopulated() {
191190
ProtoMessageValueProvider protoMessageValueProvider =
192-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
191+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
193192

194193
ProtoMessageValue protoMessageValue =
195194
(ProtoMessageValue)
@@ -210,7 +209,7 @@ public void newValue_createProtoMessage_extensionFieldsPopulated() {
210209
@Test
211210
public void newValue_invalidMessageName_throws() {
212211
ProtoMessageValueProvider protoMessageValueProvider =
213-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
212+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
214213

215214
CelRuntimeException e =
216215
assertThrows(
@@ -225,7 +224,7 @@ public void newValue_invalidMessageName_throws() {
225224
@Test
226225
public void newValue_invalidField_throws() {
227226
ProtoMessageValueProvider protoMessageValueProvider =
228-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
227+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
229228

230229
IllegalArgumentException e =
231230
assertThrows(
@@ -245,7 +244,7 @@ public void newValue_invalidField_throws() {
245244
public void newValue_onCombinedProvider() {
246245
CelValueProvider celValueProvider = (structType, fields) -> Optional.empty();
247246
ProtoMessageValueProvider protoMessageValueProvider =
248-
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.DEFAULT);
247+
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO);
249248
CelValueProvider combinedProvider =
250249
new CombinedCelValueProvider(celValueProvider, protoMessageValueProvider);
251250

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public CelRuntimeLegacyImpl build() {
292292

293293
if (options.enableCelValue()) {
294294
ProtoMessageValueProvider messageValueProvider =
295-
ProtoMessageValueProvider.newInstance(dynamicProto, options);
295+
ProtoMessageValueProvider.newInstance(dynamicProto);
296296
if (celValueProvider != null) {
297297
celValueProvider =
298298
new CelValueProvider.CombinedCelValueProvider(celValueProvider, messageValueProvider);

0 commit comments

Comments
 (0)