Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Guava checkNotNull with JDK requireNonNull #222

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/com/treasuredata/client/TDApiRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

/**
* An abstraction of TD API request, which will be translated to Jetty's http client request.
Expand Down Expand Up @@ -67,16 +67,16 @@ public class TDApiRequest
Optional<Boolean> followRedirects
)
{
this.method = checkNotNull(method, "method is null");
this.path = checkNotNull(path, "uri is null");
this.queryParams = checkNotNull(queryParams, "queryParms is null");
this.headerParams = checkNotNull(headerParams, "headerParams is null");
this.postJson = checkNotNull(postJson, "postJson is null");
this.putFile = checkNotNull(putFile, "putFile is null");
this.content = checkNotNull(content, "content is null");
this.method = requireNonNull(method, "method is null");
this.path = requireNonNull(path, "uri is null");
this.queryParams = requireNonNull(queryParams, "queryParms is null");
this.headerParams = requireNonNull(headerParams, "headerParams is null");
this.postJson = requireNonNull(postJson, "postJson is null");
this.putFile = requireNonNull(putFile, "putFile is null");
this.content = requireNonNull(content, "content is null");
this.contentOffset = contentOffset;
this.contentLength = contentLength;
this.followRedirects = checkNotNull(followRedirects, "followRedirects is null");
this.followRedirects = requireNonNull(followRedirects, "followRedirects is null");
}

public TDApiRequest withUri(String uri)
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/com/treasuredata/client/TDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
import java.util.Properties;
import java.util.regex.Pattern;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;
import static java.util.Objects.requireNonNull;

/**
*
Expand Down Expand Up @@ -189,8 +189,8 @@ protected static String buildUrl(String urlPrefix, String... args)
protected <ResultType> ResultType doGet(String path, Class<ResultType> resultTypeClass)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(resultTypeClass, "resultTypeClass is null");
requireNonNull(path, "path is null");
requireNonNull(resultTypeClass, "resultTypeClass is null");

TDApiRequest request = TDApiRequest.Builder.GET(path).build();
return httpClient.call(request, apiKeyCache, resultTypeClass);
Expand All @@ -199,8 +199,8 @@ protected <ResultType> ResultType doGet(String path, Class<ResultType> resultTyp
protected <ResultType> ResultType doGet(String path, TypeReference<ResultType> resultTypeReference)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(resultTypeReference, "resultTypeReference is null");
requireNonNull(path, "path is null");
requireNonNull(resultTypeReference, "resultTypeReference is null");

TDApiRequest request = TDApiRequest.Builder.GET(path).build();
return httpClient.call(request, apiKeyCache, resultTypeReference);
Expand All @@ -209,8 +209,8 @@ protected <ResultType> ResultType doGet(String path, TypeReference<ResultType> r
protected <ResultType> ResultType doGet(String path, JavaType resultType)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(resultType, "resultType is null");
requireNonNull(path, "path is null");
requireNonNull(resultType, "resultType is null");

TDApiRequest request = TDApiRequest.Builder.GET(path).build();
return httpClient.call(request, apiKeyCache, resultType);
Expand All @@ -219,10 +219,10 @@ protected <ResultType> ResultType doGet(String path, JavaType resultType)
protected <ResultType> ResultType doPost(String path, Map<String, String> queryParam, Optional<String> jsonBody, Class<ResultType> resultTypeClass)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(queryParam, "param is null");
checkNotNull(jsonBody, "body is null");
checkNotNull(resultTypeClass, "resultTypeClass is null");
requireNonNull(path, "path is null");
requireNonNull(queryParam, "param is null");
requireNonNull(jsonBody, "body is null");
requireNonNull(resultTypeClass, "resultTypeClass is null");

TDApiRequest.Builder request = TDApiRequest.Builder.POST(path);
for (Map.Entry<String, String> e : queryParam.entrySet()) {
Expand All @@ -249,8 +249,8 @@ protected <ResultType> ResultType doPost(String path, Map<String, String> queryP
protected <ResultType> ResultType doPut(String path, Map<String, String> queryParam, File file, Class<ResultType> resultTypeClass)
throws TDClientException
{
checkNotNull(file, "file is null");
checkNotNull(resultTypeClass, "resultTypeClass is null");
requireNonNull(file, "file is null");
requireNonNull(resultTypeClass, "resultTypeClass is null");

TDApiRequest.Builder request = buildPutRequest(path, queryParam);
request.setFile(file);
Expand All @@ -260,8 +260,8 @@ protected <ResultType> ResultType doPut(String path, Map<String, String> queryPa
protected <ResultType> ResultType doPut(String path, Map<String, String> queryParam, byte[] content, int offset, int length, Class<ResultType> resultTypeClass)
throws TDClientException
{
checkNotNull(content, "content is null");
checkNotNull(resultTypeClass, "resultTypeClass is null");
requireNonNull(content, "content is null");
requireNonNull(resultTypeClass, "resultTypeClass is null");

TDApiRequest.Builder request = buildPutRequest(path, queryParam);
request.setContent(content, offset, length);
Expand All @@ -270,8 +270,8 @@ protected <ResultType> ResultType doPut(String path, Map<String, String> queryPa

private TDApiRequest.Builder buildPutRequest(String path, Map<String, String> queryParam)
{
checkNotNull(path, "path is null");
checkNotNull(queryParam, "param is null");
requireNonNull(path, "path is null");
requireNonNull(queryParam, "param is null");

TDApiRequest.Builder request = TDApiRequest.Builder.PUT(path);
for (Map.Entry<String, String> e : queryParam.entrySet()) {
Expand All @@ -284,7 +284,7 @@ private TDApiRequest.Builder buildPutRequest(String path, Map<String, String> qu
protected String doPost(String path)
throws TDClientException
{
checkNotNull(path, "path is null");
requireNonNull(path, "path is null");

TDApiRequest request = TDApiRequest.Builder.POST(path).build();
return httpClient.call(request, apiKeyCache);
Expand All @@ -293,8 +293,8 @@ protected String doPost(String path)
protected String doPost(String path, Map<String, String> queryParam)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(queryParam, "param is null");
requireNonNull(path, "path is null");
requireNonNull(queryParam, "param is null");

TDApiRequest.Builder request = TDApiRequest.Builder.POST(path);
for (Map.Entry<String, String> e : queryParam.entrySet()) {
Expand All @@ -307,8 +307,8 @@ protected String doPost(String path, Map<String, String> queryParam)
protected String doPut(String path, File filePath)
throws TDClientException
{
checkNotNull(path, "path is null");
checkNotNull(filePath, "filePath is null");
requireNonNull(path, "path is null");
requireNonNull(filePath, "filePath is null");

TDApiRequest request = TDApiRequest.Builder.PUT(path).setFile(filePath).build();
return httpClient.call(request, apiKeyCache);
Expand Down Expand Up @@ -586,9 +586,9 @@ public void updateTableSchema(String databaseName, String tableName, List<TDColu
@Override
public void updateTableSchema(String databaseName, String tableName, List<TDColumn> newSchema, boolean ignoreDuplicate)
{
checkNotNull(databaseName, "databaseName is null");
checkNotNull(tableName, "tableName is null");
checkNotNull(newSchema, "newSchema is null");
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
requireNonNull(newSchema, "newSchema is null");

ImmutableList.Builder<List<String>> builder = ImmutableList.builder();
for (TDColumn newColumn : newSchema) {
Expand All @@ -601,9 +601,9 @@ public void updateTableSchema(String databaseName, String tableName, List<TDColu
@Override
public void appendTableSchema(String databaseName, String tableName, List<TDColumn> appendedSchema)
{
checkNotNull(databaseName, "databaseName is null");
checkNotNull(tableName, "tableName is null");
checkNotNull(appendedSchema, "appendedSchema is null");
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
requireNonNull(appendedSchema, "appendedSchema is null");

ImmutableList.Builder<List<String>> builder = ImmutableList.builder();
for (TDColumn appendedColumn : appendedSchema) {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/treasuredata/client/TDClientException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

/**
* Exception class for reporting td-client errors
Expand Down Expand Up @@ -66,10 +66,8 @@ private static final String formatErrorMessage(ErrorType errorType, String messa
public TDClientException(ErrorType errorType, String message, Optional<Exception> cause)
{
super(formatErrorMessage(errorType, message, cause), cause.orElse(null));
checkNotNull(errorType, "errorType is null");
checkNotNull(cause, "cause is null");
this.errorType = errorType;
this.rootCause = cause;
this.errorType = requireNonNull(errorType, "errorType is null");
this.rootCause = requireNonNull(cause, "cause is null");
}

public TDClientException(ErrorType errorType, String message, Exception cause)
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/treasuredata/client/TDHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.net.HttpHeaders.AUTHORIZATION;
import static com.google.common.net.HttpHeaders.CONTENT_LENGTH;
import static com.google.common.net.HttpHeaders.DATE;
Expand Down Expand Up @@ -374,9 +373,13 @@ protected <Result> Result submitRequest(RequestContext context, TDHttpRequestHan
if (executionCount > config.retryLimit) {
logger.warn("API request retry limit exceeded: ({}/{})", config.retryLimit, config.retryLimit);

checkState(context.rootCause.isPresent(), "rootCause must be present here");
// Throw the last seen error
throw context.rootCause.get();
if (context.rootCause.isPresent()) {
// Throw the last seen error
throw context.rootCause.get();
}
else {
throw new IllegalStateException("rootCause must be present here");
}
}
else {
if (executionCount == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/treasuredata/client/model/TDColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.Arrays;
import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;

public class TDColumn implements Serializable
{
Expand Down Expand Up @@ -63,9 +63,9 @@ public TDColumn(

public TDColumn(String name, TDColumnType type, byte[] key)
{
this.name = checkNotNull(name, "name is null");
this.type = checkNotNull(type, "type is null");
this.key = Arrays.copyOf(checkNotNull(key, "key is null"), key.length);
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
this.key = Arrays.copyOf(requireNonNull(key, "key is null"), key.length);
}

@JsonProperty
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/treasuredata/client/model/TDUserList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;

public class TDUserList
{
Expand All @@ -14,7 +13,7 @@ public class TDUserList
@JsonCreator
TDUserList(@JsonProperty("users") List<TDUser> users)
{
this.users = checkNotNull(users, "users");
this.users = Objects.requireNonNull(users, "users");
}

@JsonProperty("users")
Expand Down