From 0555d5faa8a2f8665c7008895b99721f3344e42d Mon Sep 17 00:00:00 2001 From: Andreas Skoog Date: Thu, 24 Aug 2023 11:58:44 +0200 Subject: [PATCH] replace usage of guava with standard java Avoid adding extra third party dependency 'guava' by replacing methods with equivalent alternatives in standard jdk. This helps users of etcd since every transitive third party dependency requires more code to be downloaded and might result in dependency conflicts. fixes #1207 Signed-off-by: Andreas Skoog --- gradle/libs.versions.toml | 2 - jetcd-common/build.gradle | 1 - .../jetcd/common/exception/EtcdException.java | 4 +- .../exception/EtcdExceptionFactory.java | 7 ++-- .../main/java/io/etcd/jetcd/ByteSequence.java | 8 ++-- .../java/io/etcd/jetcd/ClientBuilder.java | 17 ++++---- .../java/io/etcd/jetcd/Preconditions.java | 32 ++++++++++++++ .../io/etcd/jetcd/impl/AuthCredential.java | 2 +- .../java/io/etcd/jetcd/impl/AuthImpl.java | 42 +++++++++---------- .../java/io/etcd/jetcd/impl/ElectionImpl.java | 18 ++++---- .../main/java/io/etcd/jetcd/impl/KVImpl.java | 18 ++++---- .../java/io/etcd/jetcd/impl/LeaseImpl.java | 4 +- .../java/io/etcd/jetcd/impl/LockImpl.java | 6 +-- .../io/etcd/jetcd/options/DeleteOption.java | 4 +- .../java/io/etcd/jetcd/options/GetOption.java | 4 +- .../io/etcd/jetcd/options/WatchOption.java | 4 +- .../jetcd/resolver/AbstractNameResolver.java | 3 +- jetcd-grpc/build.gradle | 1 - jetcd-test/build.gradle | 1 - .../jetcd/test/EtcdClusterNameResolver.java | 3 +- 20 files changed, 105 insertions(+), 76 deletions(-) create mode 100644 jetcd-core/src/main/java/io/etcd/jetcd/Preconditions.java diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0eb27d593..e554e70c3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,6 @@ grpc = "1.57.2" log4j = "2.20.0" mockito = "5.5.0" slf4j = "2.0.7" -guava = "32.1.2-jre" assertj = "3.24.2" junit = "5.10.0" testcontainers = "1.19.0" @@ -29,7 +28,6 @@ testRetryPlugin = "1.5.3" [libraries] slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } -guava = { module = "com.google.guava:guava", version.ref = "guava" } assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" } diff --git a/jetcd-common/build.gradle b/jetcd-common/build.gradle index 4e16d87e3..ec7241b21 100644 --- a/jetcd-common/build.gradle +++ b/jetcd-common/build.gradle @@ -17,7 +17,6 @@ dependencies { api libs.slf4j - api libs.guava api libs.grpcCore testImplementation libs.bundles.testing diff --git a/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdException.java b/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdException.java index 5e92f1c62..b5e5b9060 100644 --- a/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdException.java +++ b/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdException.java @@ -16,7 +16,7 @@ package io.etcd.jetcd.common.exception; -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Objects; /** * Base exception type for all exceptions produced by the etcd service. @@ -27,7 +27,7 @@ public class EtcdException extends RuntimeException { EtcdException(ErrorCode code, String message, Throwable cause) { super(message, cause); - this.code = checkNotNull(code); + this.code = Objects.requireNonNull(code, "Error code must not be null"); } /** diff --git a/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdExceptionFactory.java b/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdExceptionFactory.java index 905e5f7f0..f8a817614 100644 --- a/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdExceptionFactory.java +++ b/jetcd-common/src/main/java/io/etcd/jetcd/common/exception/EtcdExceptionFactory.java @@ -16,9 +16,10 @@ package io.etcd.jetcd.common.exception; +import java.util.Objects; + import io.grpc.Status; -import static com.google.common.base.Preconditions.checkNotNull; import static io.grpc.Status.fromThrowable; /** @@ -65,7 +66,7 @@ public static EtcdException handleInterrupt(InterruptedException e) { } public static EtcdException toEtcdException(Throwable cause) { - checkNotNull(cause, "cause can't be null"); + Objects.requireNonNull(cause, "cause can't be null"); if (cause instanceof EtcdException) { return (EtcdException) cause; } @@ -74,7 +75,7 @@ public static EtcdException toEtcdException(Throwable cause) { } public static EtcdException toEtcdException(Status status) { - checkNotNull(status, "status can't be null"); + Objects.requireNonNull(status, "status can't be null"); return fromStatus(status); } diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/ByteSequence.java b/jetcd-core/src/main/java/io/etcd/jetcd/ByteSequence.java index dd314360f..3bcb5f447 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/ByteSequence.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/ByteSequence.java @@ -17,8 +17,8 @@ package io.etcd.jetcd; import java.nio.charset.Charset; +import java.util.Objects; -import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; /** @@ -32,7 +32,7 @@ public final class ByteSequence { private final ByteString byteString; private ByteSequence(ByteString byteString) { - Preconditions.checkNotNull(byteString, "byteString should not be null"); + Objects.requireNonNull(byteString, "byteString should not be null"); this.byteString = byteString; this.hashVal = byteString.hashCode(); } @@ -58,7 +58,7 @@ public boolean startsWith(ByteSequence prefix) { * @return a new {@code ByteSequence} instance */ public ByteSequence concat(ByteSequence other) { - Preconditions.checkNotNull(other, "other byteSequence should not be null"); + Objects.requireNonNull(other, "other byteSequence should not be null"); return new ByteSequence(this.byteString.concat(other.byteString)); } @@ -69,7 +69,7 @@ public ByteSequence concat(ByteSequence other) { * @return a new {@code ByteSequence} instance */ public ByteSequence concat(ByteString other) { - Preconditions.checkNotNull(other, "other byteSequence should not be null"); + Objects.requireNonNull(other, "other byteSequence should not be null"); return new ByteSequence(this.byteString.concat(other)); } diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/ClientBuilder.java b/jetcd-core/src/main/java/io/etcd/jetcd/ClientBuilder.java index 43f044beb..82205e359 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/ClientBuilder.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/ClientBuilder.java @@ -24,6 +24,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.stream.StreamSupport; import javax.net.ssl.SSLException; @@ -37,9 +38,7 @@ import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; -import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.collect.Streams; /** * ClientBuilder knows how to create a Client instance. @@ -131,7 +130,7 @@ public ClientBuilder endpoints(URI... endpoints) { * @throws IllegalArgumentException if some endpoint is invalid */ public ClientBuilder endpoints(Iterable endpoints) { - Preconditions.checkNotNull(endpoints, "endpoints can't be null"); + Objects.requireNonNull(endpoints, "endpoints can't be null"); endpoints.forEach(e -> { if (e.getHost() == null) { @@ -139,7 +138,7 @@ public ClientBuilder endpoints(Iterable endpoints) { } }); - final String target = Streams.stream(endpoints) + final String target = StreamSupport.stream(endpoints.spliterator(), false) .map(e -> e.getHost() + (e.getPort() != -1 ? ":" + e.getPort() : "")) .distinct() .collect(Collectors.joining(",")); @@ -173,7 +172,7 @@ public ByteSequence user() { * @throws NullPointerException if user is null */ public ClientBuilder user(ByteSequence user) { - Preconditions.checkNotNull(user, "user can't be null"); + Objects.requireNonNull(user, "user can't be null"); this.user = user; return this; } @@ -195,7 +194,7 @@ public ByteSequence password() { * @throws NullPointerException if password is null */ public ClientBuilder password(ByteSequence password) { - Preconditions.checkNotNull(password, "password can't be null"); + Objects.requireNonNull(password, "password can't be null"); this.password = password; return this; } @@ -218,7 +217,7 @@ public ByteSequence namespace() { * @throws NullPointerException if namespace is null */ public ClientBuilder namespace(ByteSequence namespace) { - Preconditions.checkNotNull(namespace, "namespace can't be null"); + Objects.requireNonNull(namespace, "namespace can't be null"); this.namespace = namespace; return this; } @@ -240,7 +239,7 @@ public ExecutorService executorService() { * @throws NullPointerException if executorService is null */ public ClientBuilder executorService(ExecutorService executorService) { - Preconditions.checkNotNull(executorService, "executorService can't be null"); + Objects.requireNonNull(executorService, "executorService can't be null"); this.executorService = executorService; return this; } @@ -253,7 +252,7 @@ public ClientBuilder executorService(ExecutorService executorService) { * @throws NullPointerException if loadBalancerPolicy is null */ public ClientBuilder loadBalancerPolicy(String loadBalancerPolicy) { - Preconditions.checkNotNull(loadBalancerPolicy, "loadBalancerPolicy can't be null"); + Objects.requireNonNull(loadBalancerPolicy, "loadBalancerPolicy can't be null"); this.loadBalancerPolicy = loadBalancerPolicy; return this; } diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/Preconditions.java b/jetcd-core/src/main/java/io/etcd/jetcd/Preconditions.java new file mode 100644 index 000000000..a3c0c63de --- /dev/null +++ b/jetcd-core/src/main/java/io/etcd/jetcd/Preconditions.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016-2023 The jetcd authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.etcd.jetcd; + +public class Preconditions { + + public static void checkArgument(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalArgumentException(errorMessage); + } + } + + public static void checkState(boolean expression, String errorMessage) { + if (!expression) { + throw new IllegalStateException(errorMessage); + } + } +} diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthCredential.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthCredential.java index 8cc7c38a8..6f116500d 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthCredential.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthCredential.java @@ -31,7 +31,7 @@ import com.google.protobuf.ByteString; -import static com.google.common.base.Preconditions.checkArgument; +import static io.etcd.jetcd.Preconditions.checkArgument; /** * AuthTokenInterceptor fills header with Auth token of any rpc calls and diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthImpl.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthImpl.java index 7c68f847e..f057c3353 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthImpl.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/AuthImpl.java @@ -55,7 +55,7 @@ import com.google.protobuf.ByteString; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Implementation of etcd auth client. @@ -88,8 +88,8 @@ public CompletableFuture authDisable() { @Override public CompletableFuture userAdd(ByteSequence user, ByteSequence password) { - checkNotNull(user, "user can't be null"); - checkNotNull(password, "password can't be null"); + requireNonNull(user, "user can't be null"); + requireNonNull(password, "password can't be null"); AuthUserAddRequest addRequest = AuthUserAddRequest.newBuilder() .setNameBytes(ByteString.copyFrom(user.getBytes())) @@ -103,7 +103,7 @@ public CompletableFuture userAdd(ByteSequence user, ByteSeq @Override public CompletableFuture userDelete(ByteSequence user) { - checkNotNull(user, "user can't be null"); + requireNonNull(user, "user can't be null"); AuthUserDeleteRequest deleteRequest = AuthUserDeleteRequest.newBuilder() .setNameBytes(ByteString.copyFrom(user.getBytes())) @@ -116,8 +116,8 @@ public CompletableFuture userDelete(ByteSequence user) { @Override public CompletableFuture userChangePassword(ByteSequence user, ByteSequence password) { - checkNotNull(user, "user can't be null"); - checkNotNull(password, "password can't be null"); + requireNonNull(user, "user can't be null"); + requireNonNull(password, "password can't be null"); AuthUserChangePasswordRequest changePasswordRequest = AuthUserChangePasswordRequest.newBuilder() .setNameBytes(ByteString.copyFrom(user.getBytes())) @@ -131,7 +131,7 @@ public CompletableFuture userChangePassword(Byte @Override public CompletableFuture userGet(ByteSequence user) { - checkNotNull(user, "user can't be null"); + requireNonNull(user, "user can't be null"); AuthUserGetRequest userGetRequest = AuthUserGetRequest.newBuilder() .setNameBytes(ByteString.copyFrom(user.getBytes())) @@ -153,8 +153,8 @@ public CompletableFuture userList() { @Override public CompletableFuture userGrantRole(ByteSequence user, ByteSequence role) { - checkNotNull(user, "user can't be null"); - checkNotNull(role, "key can't be null"); + requireNonNull(user, "user can't be null"); + requireNonNull(role, "key can't be null"); AuthUserGrantRoleRequest userGrantRoleRequest = AuthUserGrantRoleRequest.newBuilder() .setUserBytes(ByteString.copyFrom(user.getBytes())) @@ -168,8 +168,8 @@ public CompletableFuture userGrantRole(ByteSequence u @Override public CompletableFuture userRevokeRole(ByteSequence user, ByteSequence role) { - checkNotNull(user, "user can't be null"); - checkNotNull(role, "key can't be null"); + requireNonNull(user, "user can't be null"); + requireNonNull(role, "key can't be null"); AuthUserRevokeRoleRequest userRevokeRoleRequest = AuthUserRevokeRoleRequest.newBuilder() .setNameBytes(ByteString.copyFrom(user.getBytes())) @@ -183,7 +183,7 @@ public CompletableFuture userRevokeRole(ByteSequence @Override public CompletableFuture roleAdd(ByteSequence user) { - checkNotNull(user, "user can't be null"); + requireNonNull(user, "user can't be null"); AuthRoleAddRequest roleAddRequest = AuthRoleAddRequest.newBuilder().setNameBytes(ByteString.copyFrom(user.getBytes())) .build(); @@ -196,10 +196,10 @@ public CompletableFuture roleAdd(ByteSequence user) { @Override public CompletableFuture roleGrantPermission(ByteSequence role, ByteSequence key, ByteSequence rangeEnd, Permission.Type permType) { - checkNotNull(role, "role can't be null"); - checkNotNull(key, "key can't be null"); - checkNotNull(rangeEnd, "rangeEnd can't be null"); - checkNotNull(permType, "permType can't be null"); + requireNonNull(role, "role can't be null"); + requireNonNull(key, "key can't be null"); + requireNonNull(rangeEnd, "rangeEnd can't be null"); + requireNonNull(permType, "permType can't be null"); io.etcd.jetcd.api.Permission.Type type; switch (permType) { @@ -235,7 +235,7 @@ public CompletableFuture roleGrantPermission(By @Override public CompletableFuture roleGet(ByteSequence role) { - checkNotNull(role, "role can't be null"); + requireNonNull(role, "role can't be null"); AuthRoleGetRequest roleGetRequest = AuthRoleGetRequest.newBuilder() .setRoleBytes(ByteString.copyFrom(role.getBytes())) @@ -258,9 +258,9 @@ public CompletableFuture roleList() { @Override public CompletableFuture roleRevokePermission(ByteSequence role, ByteSequence key, ByteSequence rangeEnd) { - checkNotNull(role, "role can't be null"); - checkNotNull(key, "key can't be null"); - checkNotNull(rangeEnd, "rangeEnd can't be null"); + requireNonNull(role, "role can't be null"); + requireNonNull(key, "key can't be null"); + requireNonNull(rangeEnd, "rangeEnd can't be null"); AuthRoleRevokePermissionRequest roleRevokePermissionRequest = AuthRoleRevokePermissionRequest.newBuilder() .setRoleBytes(ByteString.copyFrom(role.getBytes())) @@ -275,7 +275,7 @@ public CompletableFuture roleRevokePermission( @Override public CompletableFuture roleDelete(ByteSequence role) { - checkNotNull(role, "role can't be null"); + requireNonNull(role, "role can't be null"); AuthRoleDeleteRequest roleDeleteRequest = AuthRoleDeleteRequest.newBuilder() .setRoleBytes(ByteString.copyFrom(role.getBytes())) .build(); diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/ElectionImpl.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/ElectionImpl.java index 2e2583ac6..f8a5fe5a3 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/ElectionImpl.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/ElectionImpl.java @@ -37,8 +37,8 @@ import com.google.protobuf.ByteString; -import static com.google.common.base.Preconditions.checkNotNull; import static io.etcd.jetcd.common.exception.EtcdExceptionFactory.toEtcdException; +import static java.util.Objects.requireNonNull; final class ElectionImpl extends Impl implements Election { private final VertxElectionGrpc.ElectionVertxStub stub; @@ -53,8 +53,8 @@ final class ElectionImpl extends Impl implements Election { @Override public CompletableFuture campaign(ByteSequence electionName, long leaseId, ByteSequence proposal) { - checkNotNull(electionName, "election name should not be null"); - checkNotNull(proposal, "proposal should not be null"); + requireNonNull(electionName, "election name should not be null"); + requireNonNull(proposal, "proposal should not be null"); CampaignRequest request = CampaignRequest.newBuilder() .setName(Util.prefixNamespace(electionName, namespace)) @@ -70,8 +70,8 @@ public CompletableFuture campaign(ByteSequence electionName, l @Override public CompletableFuture proclaim(LeaderKey leaderKey, ByteSequence proposal) { - checkNotNull(leaderKey, "leader key should not be null"); - checkNotNull(proposal, "proposal should not be null"); + requireNonNull(leaderKey, "leader key should not be null"); + requireNonNull(proposal, "proposal should not be null"); ProclaimRequest request = ProclaimRequest.newBuilder() .setLeader( @@ -92,7 +92,7 @@ public CompletableFuture proclaim(LeaderKey leaderKey, ByteSeq @Override public CompletableFuture leader(ByteSequence electionName) { - checkNotNull(electionName, "election name should not be null"); + requireNonNull(electionName, "election name should not be null"); LeaderRequest request = LeaderRequest.newBuilder() .setName(Util.prefixNamespace(electionName, namespace)) @@ -106,8 +106,8 @@ public CompletableFuture leader(ByteSequence electionName) { @Override public void observe(ByteSequence electionName, Listener listener) { - checkNotNull(electionName, "election name should not be null"); - checkNotNull(listener, "listener should not be null"); + requireNonNull(electionName, "election name should not be null"); + requireNonNull(listener, "listener should not be null"); LeaderRequest request = LeaderRequest.newBuilder() .setName(ByteString.copyFrom(electionName.getBytes())) @@ -121,7 +121,7 @@ public void observe(ByteSequence electionName, Listener listener) { @Override public CompletableFuture resign(LeaderKey leaderKey) { - checkNotNull(leaderKey, "leader key should not be null"); + requireNonNull(leaderKey, "leader key should not be null"); ResignRequest request = ResignRequest.newBuilder() .setLeader( diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/KVImpl.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/KVImpl.java index 01e0c9f01..4baf11e1e 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/KVImpl.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/KVImpl.java @@ -36,7 +36,7 @@ import io.etcd.jetcd.support.Errors; import io.etcd.jetcd.support.Requests; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Implementation of etcd kv client. @@ -59,9 +59,9 @@ public CompletableFuture put(ByteSequence key, ByteSequence value) @Override public CompletableFuture put(ByteSequence key, ByteSequence value, PutOption option) { - checkNotNull(key, "key should not be null"); - checkNotNull(value, "value should not be null"); - checkNotNull(option, "option should not be null"); + requireNonNull(key, "key should not be null"); + requireNonNull(value, "value should not be null"); + requireNonNull(option, "option should not be null"); return execute( () -> stub.put(Requests.mapPutRequest(key, value, option, namespace)), response -> new PutResponse(response, namespace), @@ -75,8 +75,8 @@ public CompletableFuture get(ByteSequence key) { @Override public CompletableFuture get(ByteSequence key, GetOption option) { - checkNotNull(key, "key should not be null"); - checkNotNull(option, "option should not be null"); + requireNonNull(key, "key should not be null"); + requireNonNull(option, "option should not be null"); return execute( () -> stub.range(Requests.mapRangeRequest(key, option, namespace)), @@ -91,8 +91,8 @@ public CompletableFuture delete(ByteSequence key) { @Override public CompletableFuture delete(ByteSequence key, DeleteOption option) { - checkNotNull(key, "key should not be null"); - checkNotNull(option, "option should not be null"); + requireNonNull(key, "key should not be null"); + requireNonNull(option, "option should not be null"); return execute( () -> stub.deleteRange(Requests.mapDeleteRequest(key, option, namespace)), @@ -107,7 +107,7 @@ public CompletableFuture compact(long rev) { @Override public CompletableFuture compact(long rev, CompactOption option) { - checkNotNull(option, "option should not be null"); + requireNonNull(option, "option should not be null"); CompactionRequest request = CompactionRequest.newBuilder() .setRevision(rev).setPhysical(option.isPhysical()) diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/LeaseImpl.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/LeaseImpl.java index 2236ee0e1..f92058f82 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/LeaseImpl.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/LeaseImpl.java @@ -39,8 +39,8 @@ import io.grpc.stub.StreamObserver; import io.vertx.core.streams.WriteStream; -import static com.google.common.base.Preconditions.checkNotNull; import static io.etcd.jetcd.common.exception.EtcdExceptionFactory.*; +import static java.util.Objects.requireNonNull; /** * Implementation of lease client. @@ -102,7 +102,7 @@ public CompletableFuture revoke(long leaseId) { @Override public CompletableFuture timeToLive(long leaseId, LeaseOption option) { - checkNotNull(option, "LeaseOption should not be null"); + requireNonNull(option, "LeaseOption should not be null"); LeaseTimeToLiveRequest leaseTimeToLiveRequest = LeaseTimeToLiveRequest.newBuilder() .setID(leaseId) diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/impl/LockImpl.java b/jetcd-core/src/main/java/io/etcd/jetcd/impl/LockImpl.java index 4f9b9b5e5..191aabe64 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/impl/LockImpl.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/impl/LockImpl.java @@ -28,7 +28,7 @@ import io.etcd.jetcd.support.Errors; import io.etcd.jetcd.support.Util; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; final class LockImpl extends Impl implements Lock { private final VertxLockGrpc.LockVertxStub stub; @@ -43,7 +43,7 @@ final class LockImpl extends Impl implements Lock { @Override public CompletableFuture lock(ByteSequence name, long leaseId) { - checkNotNull(name); + requireNonNull(name); LockRequest request = LockRequest.newBuilder() .setName(Util.prefixNamespace(name, namespace)) @@ -58,7 +58,7 @@ public CompletableFuture lock(ByteSequence name, long leaseId) { @Override public CompletableFuture unlock(ByteSequence lockKey) { - checkNotNull(lockKey); + requireNonNull(lockKey); UnlockRequest request = UnlockRequest.newBuilder() .setKey(Util.prefixNamespace(lockKey, namespace)) diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/options/DeleteOption.java b/jetcd-core/src/main/java/io/etcd/jetcd/options/DeleteOption.java index d902a262b..fb1113824 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/options/DeleteOption.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/options/DeleteOption.java @@ -21,7 +21,7 @@ import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.KV; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; public final class DeleteOption { public static final DeleteOption DEFAULT = builder().build(); @@ -127,7 +127,7 @@ public DeleteOption.Builder isPrefix(boolean prefix) { */ @Deprecated public Builder withPrefix(ByteSequence prefix) { - checkNotNull(prefix, "prefix should not be null"); + requireNonNull(prefix, "prefix should not be null"); ByteSequence prefixEnd = OptionsUtil.prefixEndOf(prefix); this.withRange(prefixEnd); return this; diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/options/GetOption.java b/jetcd-core/src/main/java/io/etcd/jetcd/options/GetOption.java index 3173b74b7..c638ba7d5 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/options/GetOption.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/options/GetOption.java @@ -21,7 +21,7 @@ import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.KV; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * The option for get operation. @@ -309,7 +309,7 @@ public Builder isPrefix(boolean prefix) { */ @Deprecated public Builder withPrefix(ByteSequence prefix) { - checkNotNull(prefix, "prefix should not be null"); + requireNonNull(prefix, "prefix should not be null"); ByteSequence prefixEnd = OptionsUtil.prefixEndOf(prefix); this.withRange(prefixEnd); return this; diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/options/WatchOption.java b/jetcd-core/src/main/java/io/etcd/jetcd/options/WatchOption.java index 521e63ae7..3df6d07f5 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/options/WatchOption.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/options/WatchOption.java @@ -20,7 +20,7 @@ import io.etcd.jetcd.ByteSequence; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * The option for watch operation. @@ -273,7 +273,7 @@ public WatchOption.Builder isPrefix(boolean prefix) { */ @Deprecated public Builder withPrefix(ByteSequence prefix) { - checkNotNull(prefix, "prefix should not be null"); + requireNonNull(prefix, "prefix should not be null"); ByteSequence prefixEnd = OptionsUtil.prefixEndOf(prefix); this.withRange(prefixEnd); return this; diff --git a/jetcd-core/src/main/java/io/etcd/jetcd/resolver/AbstractNameResolver.java b/jetcd-core/src/main/java/io/etcd/jetcd/resolver/AbstractNameResolver.java index 787f99781..8e8078ce1 100644 --- a/jetcd-core/src/main/java/io/etcd/jetcd/resolver/AbstractNameResolver.java +++ b/jetcd-core/src/main/java/io/etcd/jetcd/resolver/AbstractNameResolver.java @@ -18,6 +18,7 @@ import java.net.URI; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executor; import org.slf4j.Logger; @@ -69,7 +70,7 @@ public void start(Listener listener) { synchronized (lock) { Preconditions.checkState(this.listener == null, "already started"); this.executor = SharedResourceHolder.get(GrpcUtil.SHARED_CHANNEL_EXECUTOR); - this.listener = Preconditions.checkNotNull(listener, "listener"); + this.listener = Objects.requireNonNull(listener, "listener"); resolve(); } } diff --git a/jetcd-grpc/build.gradle b/jetcd-grpc/build.gradle index 5e0099dd6..3faec0065 100644 --- a/jetcd-grpc/build.gradle +++ b/jetcd-grpc/build.gradle @@ -21,7 +21,6 @@ plugins { dependencies { api libs.slf4j api libs.vertxGrpc - api libs.guava api libs.bundles.grpc } diff --git a/jetcd-test/build.gradle b/jetcd-test/build.gradle index 493363f38..4ddfb5bd4 100644 --- a/jetcd-test/build.gradle +++ b/jetcd-test/build.gradle @@ -19,7 +19,6 @@ dependencies { api project(':jetcd-launcher') api libs.slf4j - api libs.guava api libs.bundles.grpc api libs.junit api libs.autoServiceAnnotations diff --git a/jetcd-test/src/main/java/io/etcd/jetcd/test/EtcdClusterNameResolver.java b/jetcd-test/src/main/java/io/etcd/jetcd/test/EtcdClusterNameResolver.java index f666ac0e6..ab4865b49 100644 --- a/jetcd-test/src/main/java/io/etcd/jetcd/test/EtcdClusterNameResolver.java +++ b/jetcd-test/src/main/java/io/etcd/jetcd/test/EtcdClusterNameResolver.java @@ -19,6 +19,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executor; import org.slf4j.Logger; @@ -65,7 +66,7 @@ public void start(Listener listener) { synchronized (lock) { Preconditions.checkState(this.listener == null, "already started"); this.executor = SharedResourceHolder.get(GrpcUtil.SHARED_CHANNEL_EXECUTOR); - this.listener = Preconditions.checkNotNull(listener, "listener"); + this.listener = Objects.requireNonNull(listener, "listener"); resolve(); } }