Skip to content

Commit 361d7df

Browse files
committed
Remove guava dependency
1 parent 198eb5e commit 361d7df

23 files changed

+167
-179
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ mavenPublishing {
257257

258258
dependencies {
259259
annotationProcessor(libs.nullaway)
260+
api(libs.jspecify)
260261
api(libs.protobuf.java)
261262
implementation(enforcedPlatform(libs.cel))
262263
implementation(libs.cel.core)
263-
implementation(libs.guava)
264264

265265
buf("build.buf:buf:${libs.versions.buf.get()}:${osdetector.classifier}@exe")
266266

@@ -269,5 +269,5 @@ dependencies {
269269
testImplementation("org.junit.jupiter:junit-jupiter")
270270
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
271271

272-
errorprone(libs.errorprone)
272+
errorprone(libs.errorprone.core)
273273
}

conformance/build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ plugins {
1010
alias(libs.plugins.osdetector)
1111
}
1212

13+
// Conformance tests aren't bound by lowest common library version.
14+
java {
15+
sourceCompatibility = JavaVersion.VERSION_21
16+
targetCompatibility = JavaVersion.VERSION_21
17+
}
18+
1319
val buf: Configuration by configurations.creating
1420

1521
tasks.register("configureBuf") {
@@ -116,7 +122,7 @@ configure<SpotlessExtension> {
116122

117123
dependencies {
118124
implementation(project(":"))
119-
implementation(libs.guava)
125+
implementation(libs.errorprone.annotations)
120126
implementation(libs.protobuf.java)
121127

122128
implementation(libs.assertj)
@@ -127,5 +133,5 @@ dependencies {
127133
testImplementation("org.junit.jupiter:junit-jupiter")
128134
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
129135

130-
errorprone(libs.errorprone)
136+
errorprone(libs.errorprone.core)
131137
}

conformance/src/main/java/build/buf/protovalidate/conformance/Main.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import build.buf.validate.conformance.harness.TestConformanceRequest;
2525
import build.buf.validate.conformance.harness.TestConformanceResponse;
2626
import build.buf.validate.conformance.harness.TestResult;
27-
import com.google.common.base.Splitter;
2827
import com.google.errorprone.annotations.FormatMethod;
2928
import com.google.protobuf.Any;
3029
import com.google.protobuf.ByteString;
@@ -34,7 +33,6 @@
3433
import com.google.protobuf.InvalidProtocolBufferException;
3534
import com.google.protobuf.TypeRegistry;
3635
import java.util.HashMap;
37-
import java.util.List;
3836
import java.util.Map;
3937

4038
public class Main {
@@ -84,8 +82,11 @@ static TestConformanceResponse testConformance(TestConformanceRequest request) {
8482
static TestResult testCase(
8583
Validator validator, Map<String, Descriptors.Descriptor> fileDescriptors, Any testCase)
8684
throws InvalidProtocolBufferException {
87-
List<String> urlParts = Splitter.on('/').limit(2).splitToList(testCase.getTypeUrl());
88-
String fullName = urlParts.get(urlParts.size() - 1);
85+
String fullName = testCase.getTypeUrl();
86+
int slash = fullName.indexOf('/');
87+
if (slash != -1) {
88+
fullName = fullName.substring(slash + 1);
89+
}
8990
Descriptors.Descriptor descriptor = fileDescriptors.get(fullName);
9091
if (descriptor == null) {
9192
return unexpectedErrorResult("Unable to find descriptor: %s", fullName);

gradle/libs.versions.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
assertj = "3.27.3"
33
buf = "1.52.1"
44
cel = "0.5.1"
5+
error-prone = "2.37.0"
56
junit = "5.12.1"
67
maven-publish = "0.31.0"
78
# When updating, make sure to update versions in the following files to match and regenerate code with 'make generate'.
@@ -16,8 +17,9 @@ assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }
1617
buf = { module = "build.buf:buf", version.ref = "buf" }
1718
cel = { module = "org.projectnessie.cel:cel-bom", version.ref = "cel" }
1819
cel-core = { module = "org.projectnessie.cel:cel-core" }
19-
errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.37.0" }
20-
guava = { module = "com.google.guava:guava", version = "33.4.0-jre" }
20+
errorprone-annotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "error-prone" }
21+
errorprone-core = { module = "com.google.errorprone:error_prone_core", version.ref = "error-prone" }
22+
jspecify = { module ="org.jspecify:jspecify", version = "1.0.0" }
2123
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
2224
maven-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }
2325
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.12.6" }

src/main/java/build/buf/protovalidate/CelPrograms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import build.buf.protovalidate.exceptions.ExecutionException;
1818
import java.util.ArrayList;
1919
import java.util.List;
20-
import javax.annotation.Nullable;
20+
import org.jspecify.annotations.Nullable;
2121

2222
/** Evaluator that executes a {@link CompiledProgram}. */
2323
class CelPrograms implements Evaluator {

src/main/java/build/buf/protovalidate/CompiledProgram.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import build.buf.protovalidate.exceptions.ExecutionException;
1818
import build.buf.validate.FieldPath;
19-
import javax.annotation.Nullable;
19+
import org.jspecify.annotations.Nullable;
2020
import org.projectnessie.cel.Program;
2121
import org.projectnessie.cel.common.types.Err;
2222
import org.projectnessie.cel.common.types.ref.Val;
@@ -63,8 +63,7 @@ public CompiledProgram(
6363
* violations.
6464
* @throws ExecutionException If the evaluation of the CEL program fails with an error.
6565
*/
66-
@Nullable
67-
public ConstraintViolation.Builder eval(Value fieldValue, Variable bindings)
66+
public ConstraintViolation.@Nullable Builder eval(Value fieldValue, Variable bindings)
6867
throws ExecutionException {
6968
Program.EvalResult evalResult = program.eval(bindings);
7069
Val val = evalResult.getVal();

src/main/java/build/buf/protovalidate/ConstraintCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.List;
3333
import java.util.Map;
3434
import java.util.concurrent.ConcurrentHashMap;
35-
import javax.annotation.Nullable;
35+
import org.jspecify.annotations.Nullable;
3636
import org.projectnessie.cel.Ast;
3737
import org.projectnessie.cel.Env;
3838
import org.projectnessie.cel.EnvOption;
@@ -199,7 +199,7 @@ public List<CompiledProgram> compile(
199199
return celRules;
200200
}
201201

202-
private @Nullable build.buf.validate.PredefinedConstraints getFieldConstraints(
202+
private build.buf.validate.@Nullable PredefinedConstraints getFieldConstraints(
203203
FieldDescriptor constraintFieldDesc) throws CompilationException {
204204
DescriptorProtos.FieldOptions options = constraintFieldDesc.getOptions();
205205
// If the protovalidate field option is unknown, reparse options using our extension registry.

src/main/java/build/buf/protovalidate/ConstraintViolation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Deque;
2424
import java.util.List;
2525
import java.util.Objects;
26-
import javax.annotation.Nullable;
26+
import org.jspecify.annotations.Nullable;
2727

2828
/**
2929
* {@link ConstraintViolation} contains all of the collected information about an individual

src/main/java/build/buf/protovalidate/ConstraintViolationHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import build.buf.validate.FieldPathElement;
1919
import java.util.ArrayList;
2020
import java.util.List;
21-
import javax.annotation.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222

2323
class ConstraintViolationHelper {
2424
private static final List<FieldPathElement> EMPTY_PREFIX = new ArrayList<>();
@@ -46,8 +46,7 @@ class ConstraintViolationHelper {
4646
this.fieldPathElement = null;
4747
}
4848

49-
@Nullable
50-
FieldPathElement getFieldPathElement() {
49+
@Nullable FieldPathElement getFieldPathElement() {
5150
return fieldPathElement;
5251
}
5352

src/main/java/build/buf/protovalidate/CustomOverload.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package build.buf.protovalidate;
1616

17-
import com.google.common.primitives.Bytes;
1817
import java.util.HashSet;
1918
import java.util.Set;
2019
import java.util.regex.Pattern;
@@ -205,12 +204,34 @@ private static Overload celContains() {
205204
if (lhsType == TypeEnum.Bytes) {
206205
byte[] receiver = (byte[]) lhs.value();
207206
byte[] param = (byte[]) rhs.value();
208-
return Types.boolOf(Bytes.indexOf(receiver, param) != -1);
207+
return Types.boolOf(bytesContains(receiver, param));
209208
}
210209
return Err.noSuchOverload(lhs, OVERLOAD_CONTAINS, rhs);
211210
});
212211
}
213212

213+
static boolean bytesContains(byte[] arr, byte[] subArr) {
214+
if (subArr.length == 0) {
215+
return true;
216+
}
217+
if (subArr.length > arr.length) {
218+
return false;
219+
}
220+
for (int i = 0; i < arr.length - subArr.length + 1; i++) {
221+
boolean found = true;
222+
for (int j = 0; j < subArr.length; j++) {
223+
if (arr[i + j] != subArr[j]) {
224+
found = false;
225+
break;
226+
}
227+
}
228+
if (found) {
229+
return true;
230+
}
231+
}
232+
return false;
233+
}
234+
214235
/**
215236
* Creates a custom binary function overload for the "isHostname" operation.
216237
*

src/main/java/build/buf/protovalidate/DescriptorMappings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.protobuf.Descriptors.OneofDescriptor;
2222
import java.util.HashMap;
2323
import java.util.Map;
24-
import javax.annotation.Nullable;
24+
import org.jspecify.annotations.Nullable;
2525
import org.projectnessie.cel.checker.Decls;
2626

2727
/**

src/main/java/build/buf/protovalidate/EvaluatorBuilder.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import build.buf.validate.Ignore;
2323
import build.buf.validate.MessageConstraints;
2424
import build.buf.validate.OneofConstraints;
25-
import com.google.common.collect.ImmutableMap;
2625
import com.google.protobuf.ByteString;
2726
import com.google.protobuf.Descriptors;
2827
import com.google.protobuf.Descriptors.Descriptor;
@@ -35,8 +34,9 @@
3534
import java.util.Collections;
3635
import java.util.HashMap;
3736
import java.util.List;
37+
import java.util.Map;
3838
import java.util.Objects;
39-
import javax.annotation.Nullable;
39+
import org.jspecify.annotations.Nullable;
4040
import org.projectnessie.cel.Env;
4141
import org.projectnessie.cel.EnvOption;
4242
import org.projectnessie.cel.checker.Decls;
@@ -47,7 +47,7 @@ class EvaluatorBuilder {
4747
FieldPathUtils.fieldPathElement(
4848
FieldConstraints.getDescriptor().findFieldByNumber(FieldConstraints.CEL_FIELD_NUMBER));
4949

50-
private volatile ImmutableMap<Descriptor, MessageEvaluator> evaluatorCache = ImmutableMap.of();
50+
private volatile Map<Descriptor, MessageEvaluator> evaluatorCache = Collections.emptyMap();
5151

5252
private final Env env;
5353
private final boolean disableLazy;
@@ -98,7 +98,7 @@ private Evaluator build(Descriptor desc) throws CompilationException {
9898
return eval;
9999
}
100100
// Rebuild cache with this descriptor (and any of its dependencies).
101-
ImmutableMap<Descriptor, MessageEvaluator> updatedCache =
101+
Map<Descriptor, MessageEvaluator> updatedCache =
102102
new DescriptorCacheBuilder(env, constraints, evaluatorCache).build(desc);
103103
evaluatorCache = updatedCache;
104104
eval = updatedCache.get(desc);
@@ -117,9 +117,7 @@ private static class DescriptorCacheBuilder {
117117
private final HashMap<Descriptor, MessageEvaluator> cache;
118118

119119
private DescriptorCacheBuilder(
120-
Env env,
121-
ConstraintCache constraintCache,
122-
ImmutableMap<Descriptor, MessageEvaluator> previousCache) {
120+
Env env, ConstraintCache constraintCache, Map<Descriptor, MessageEvaluator> previousCache) {
123121
this.env = Objects.requireNonNull(env, "env");
124122
this.constraintCache = Objects.requireNonNull(constraintCache, "constraintCache");
125123
this.cache = new HashMap<>(previousCache);
@@ -130,13 +128,13 @@ private DescriptorCacheBuilder(
130128
* references).
131129
*
132130
* @param descriptor Descriptor used to build the cache.
133-
* @return Immutable map of descriptors to evaluators.
131+
* @return Unmodifiable map of descriptors to evaluators.
134132
* @throws CompilationException If an error occurs compiling a constraint on the cache.
135133
*/
136-
public ImmutableMap<Descriptor, MessageEvaluator> build(Descriptor descriptor)
134+
public Map<Descriptor, MessageEvaluator> build(Descriptor descriptor)
137135
throws CompilationException {
138136
createMessageEvaluator(descriptor);
139-
return ImmutableMap.copyOf(cache);
137+
return Collections.unmodifiableMap(cache);
140138
}
141139

142140
private MessageEvaluator createMessageEvaluator(Descriptor desc) throws CompilationException {
@@ -234,12 +232,10 @@ private FieldEvaluator buildField(
234232
return fieldEvaluator;
235233
}
236234

237-
@SuppressWarnings("deprecation")
238235
private boolean shouldSkip(FieldConstraints constraints) {
239236
return constraints.getIgnore() == Ignore.IGNORE_ALWAYS;
240237
}
241238

242-
@SuppressWarnings("deprecation")
243239
private static boolean shouldIgnoreEmpty(FieldConstraints constraints) {
244240
return constraints.getIgnore() == Ignore.IGNORE_IF_UNPOPULATED
245241
|| constraints.getIgnore() == Ignore.IGNORE_IF_DEFAULT_VALUE;

src/main/java/build/buf/protovalidate/FieldEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.Objects;
25-
import javax.annotation.Nullable;
25+
import org.jspecify.annotations.Nullable;
2626

2727
/** Performs validation on a single message field, defined by its descriptor. */
2828
class FieldEvaluator implements Evaluator {

src/main/java/build/buf/protovalidate/FieldPathUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import build.buf.validate.FieldPathElement;
1919
import com.google.protobuf.Descriptors;
2020
import java.util.List;
21-
import javax.annotation.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222

2323
/** Utility class for manipulating error paths in violations. */
2424
final class FieldPathUtils {

src/main/java/build/buf/protovalidate/Ipv6.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import java.util.ArrayList;
1818
import java.util.List;
19-
import javax.annotation.Nullable;
19+
import org.jspecify.annotations.Nullable;
2020

2121
/**
2222
* Ipv6 is a class used to parse a given string to determine if it is an IPv6 address or address

src/main/java/build/buf/protovalidate/MessageValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121
import java.util.Map;
22-
import javax.annotation.Nullable;
22+
import org.jspecify.annotations.Nullable;
2323

2424
/** The {@link Value} type that contains a {@link com.google.protobuf.Message}. */
2525
final class MessageValue implements Value {
@@ -37,7 +37,7 @@ public MessageValue(Message value) {
3737
}
3838

3939
@Override
40-
public @Nullable Descriptors.FieldDescriptor fieldDescriptor() {
40+
public Descriptors.@Nullable FieldDescriptor fieldDescriptor() {
4141
return null;
4242
}
4343

src/main/java/build/buf/protovalidate/NowVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package build.buf.protovalidate;
1616

1717
import java.time.Instant;
18-
import javax.annotation.Nullable;
18+
import org.jspecify.annotations.Nullable;
1919
import org.projectnessie.cel.common.types.TimestampT;
2020
import org.projectnessie.cel.interpreter.Activation;
2121
import org.projectnessie.cel.interpreter.ResolvedValue;

src/main/java/build/buf/protovalidate/ObjectValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.List;
2424
import java.util.Map;
25-
import javax.annotation.Nullable;
25+
import org.jspecify.annotations.Nullable;
2626
import org.projectnessie.cel.common.ULong;
2727

2828
/** The {@link Value} type that contains a field descriptor and its value. */

src/main/java/build/buf/protovalidate/Value.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.google.protobuf.Message;
1919
import java.util.List;
2020
import java.util.Map;
21-
import javax.annotation.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222

2323
/**
2424
* {@link Value} is a wrapper around a protobuf value that provides helper methods for accessing the
@@ -31,17 +31,15 @@ interface Value {
3131
* @return The underlying {@link Descriptors.FieldDescriptor}. null if the underlying value is not
3232
* a message field.
3333
*/
34-
@Nullable
35-
Descriptors.FieldDescriptor fieldDescriptor();
34+
Descriptors.@Nullable FieldDescriptor fieldDescriptor();
3635

3736
/**
3837
* Get the underlying value as a {@link Message} type.
3938
*
4039
* @return The underlying {@link Message} value. null if the underlying value is not a {@link
4140
* Message} type.
4241
*/
43-
@Nullable
44-
Message messageValue();
42+
@Nullable Message messageValue();
4543

4644
/**
4745
* Get the underlying value and cast it to the class type.

0 commit comments

Comments
 (0)