Skip to content

Use JDK Objects requireNonNull over Guava checkNotNull #1981

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

Merged
merged 3 commits into from
Mar 30, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.core;

import java.util.Objects;

import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.command.AuthCmd;
import com.github.dockerjava.api.command.BuildImageCmd;
Expand Down Expand Up @@ -160,8 +162,6 @@
import com.github.dockerjava.core.exec.VersionCmdExec;
import com.github.dockerjava.core.exec.WaitContainerCmdExec;

import static com.google.common.base.Preconditions.checkNotNull;

public abstract class AbstractDockerCmdExecFactory implements DockerCmdExecFactory, DockerClientConfigAware {

private DockerClientConfig dockerClientConfig;
Expand All @@ -170,15 +170,14 @@ public abstract class AbstractDockerCmdExecFactory implements DockerCmdExecFacto
protected Integer readTimeout;

protected DockerClientConfig getDockerClientConfig() {
checkNotNull(dockerClientConfig,
Objects.requireNonNull(dockerClientConfig,
"Factor not initialized, dockerClientConfig not set. You probably forgot to call init()!");
return dockerClientConfig;
}

@Override
public void init(DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
this.dockerClientConfig = dockerClientConfig;
this.dockerClientConfig = Objects.requireNonNull(dockerClientConfig, "config was not specified");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.commons.lang3.BooleanUtils.isTrue;

/**
Expand Down Expand Up @@ -362,7 +362,7 @@ public Builder withProperties(Properties p) {
* configure DOCKER_HOST
*/
public final Builder withDockerHost(String dockerHost) {
checkNotNull(dockerHost, "uri was not specified");
Objects.requireNonNull(dockerHost, "uri was not specified");
this.dockerHost = URI.create(dockerHost);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

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

/**
* @author Konstantin Pelykh (kpelykh@gmail.com)
Expand All @@ -186,8 +185,7 @@ public class DockerClientImpl implements Closeable, DockerClient {
DockerCmdExecFactory dockerCmdExecFactory;

DockerClientImpl(DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
this.dockerClientConfig = dockerClientConfig;
this.dockerClientConfig = Objects.requireNonNull(dockerClientConfig, "config was not specified");
}

/**
Expand Down Expand Up @@ -248,7 +246,7 @@ public DockerHttpClient getHttpClient() {
*/
@Deprecated
public DockerClientImpl withDockerCmdExecFactory(DockerCmdExecFactory dockerCmdExecFactory) {
checkNotNull(dockerCmdExecFactory, "dockerCmdExecFactory was not specified");
Objects.requireNonNull(dockerCmdExecFactory, "dockerCmdExecFactory was not specified");
this.dockerCmdExecFactory = dockerCmdExecFactory;
if (dockerCmdExecFactory instanceof DockerClientConfigAware) {
((DockerClientConfigAware) dockerCmdExecFactory).init(dockerClientConfig);
Expand All @@ -258,14 +256,14 @@ public DockerClientImpl withDockerCmdExecFactory(DockerCmdExecFactory dockerCmdE

@Deprecated
private DockerCmdExecFactory getDockerCmdExecFactory() {
checkNotNull(dockerCmdExecFactory, "dockerCmdExecFactory was not specified");
Objects.requireNonNull(dockerCmdExecFactory, "dockerCmdExecFactory was not specified");
return dockerCmdExecFactory;
}

@Override
public AuthConfig authConfig() {
checkNotNull(dockerClientConfig.getRegistryUsername(), "Configured username is null.");
checkNotNull(dockerClientConfig.getRegistryUrl(), "Configured serverAddress is null.");
Objects.requireNonNull(dockerClientConfig.getRegistryUsername(), "Configured username is null.");
Objects.requireNonNull(dockerClientConfig.getRegistryUrl(), "Configured serverAddress is null.");

return new AuthConfig()
.withUsername(dockerClientConfig.getRegistryUsername())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.dockerjava.core;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -14,6 +12,7 @@
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Objects;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
Expand All @@ -37,8 +36,7 @@ public class KeystoreSSLConfig implements SSLConfig, Serializable {
*/
public KeystoreSSLConfig(KeyStore keystore, String keystorePassword) {
this.keystorePassword = keystorePassword;
checkNotNull(keystore);
this.keystore = keystore;
this.keystore = Objects.requireNonNull(keystore);
}

/**
Expand All @@ -54,8 +52,8 @@ public KeystoreSSLConfig(KeyStore keystore, String keystorePassword) {
*/
public KeystoreSSLConfig(File pfxFile, String password) throws KeyStoreException, IOException,
CertificateException, NoSuchAlgorithmException {
checkNotNull(pfxFile);
checkNotNull(password);
Objects.requireNonNull(pfxFile);
Objects.requireNonNull(password);
keystore = KeyStore.getInstance("pkcs12");
try (FileInputStream fs = new FileInputStream(pfxFile)) {
keystore.load(fs, password.toCharArray());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.dockerjava.core;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Security;
import java.util.Objects;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
Expand All @@ -29,8 +28,7 @@ public class LocalDirectorySSLConfig implements SSLConfig, Serializable {
private final String dockerCertPath;

public LocalDirectorySSLConfig(String dockerCertPath) {
checkNotNull(dockerCertPath);
this.dockerCertPath = dockerCertPath;
this.dockerCertPath = Objects.requireNonNull(dockerCertPath);
}

public String getDockerCertPath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.dockerjava.core.command;

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

import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.AsyncDockerCmd;
Expand All @@ -12,8 +12,7 @@ public abstract class AbstrAsyncDockerCmd<CMD_T extends AsyncDockerCmd<CMD_T, A_
protected transient DockerCmdAsyncExec<CMD_T, A_RES_T> execution;

public AbstrAsyncDockerCmd(DockerCmdAsyncExec<CMD_T, A_RES_T> execution) {
checkNotNull(execution, "execution was not specified");
this.execution = execution;
this.execution = Objects.requireNonNull(execution, "execution was not specified");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.github.dockerjava.core.command;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.IOException;
import java.util.Base64;
import java.util.Objects;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
Expand All @@ -24,8 +23,7 @@ public abstract class AbstrDockerCmd<CMD_T extends DockerCmd<RES_T>, RES_T> impl
protected transient DockerCmdSyncExec<CMD_T, RES_T> execution;

public AbstrDockerCmd(DockerCmdSyncExec<CMD_T, RES_T> execution) {
checkNotNull(execution, "execution was not specified");
this.execution = execution;
this.execution = Objects.requireNonNull(execution, "execution was not specified");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.github.dockerjava.core.command;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.InputStream;
import java.util.Objects;

import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.model.Frame;
Expand Down Expand Up @@ -61,7 +60,7 @@ public InputStream getStdin() {

@Override
public AttachContainerCmd withContainerId(String containerId) {
checkNotNull(containerId, "containerId was not specified");
Objects.requireNonNull(containerId, "containerId was not specified");
this.containerId = containerId;
return this;
}
Expand Down Expand Up @@ -92,8 +91,7 @@ public AttachContainerCmd withStdErr(Boolean stderr) {

@Override
public AttachContainerCmd withStdIn(InputStream stdin) {
checkNotNull(stdin, "stdin was not specified");
this.stdin = stdin;
this.stdin = Objects.requireNonNull(stdin, "stdin was not specified");
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Build an image from Dockerfile.
*/
Expand Down Expand Up @@ -79,7 +78,7 @@ public BuildImageCmdImpl(BuildImageCmd.Exec exec) {

public BuildImageCmdImpl(BuildImageCmd.Exec exec, File dockerFileOrFolder) {
super(exec);
checkNotNull(dockerFileOrFolder, "dockerFolder is null");
Objects.requireNonNull(dockerFileOrFolder, "dockerFolder is null");

if (dockerFileOrFolder.isDirectory()) {
withBaseDirectory(dockerFileOrFolder);
Expand All @@ -91,7 +90,7 @@ public BuildImageCmdImpl(BuildImageCmd.Exec exec, File dockerFileOrFolder) {

public BuildImageCmdImpl(BuildImageCmd.Exec exec, InputStream tarInputStream) {
super(exec);
checkNotNull(tarInputStream, "tarInputStream is null");
Objects.requireNonNull(tarInputStream, "tarInputStream is null");
withTarInputStream(tarInputStream);
}

Expand Down Expand Up @@ -232,8 +231,7 @@ public Set<String> getExtraHosts() {
@Deprecated
@Override
public BuildImageCmdImpl withTag(String tag) {
checkNotNull(tag, "Tag is null");
this.tag = tag;
this.tag = Objects.requireNonNull(tag, "Tag is null");
return this;
}

Expand Down Expand Up @@ -328,7 +326,7 @@ public BuildImageCmd withBaseDirectory(File baseDirectory) {

@Override
public BuildImageCmdImpl withDockerfile(File dockerfile) {
checkNotNull(dockerfile);
Objects.requireNonNull(dockerfile);
if (!dockerfile.exists()) {
throw new IllegalArgumentException("Dockerfile does not exist");
}
Expand All @@ -353,22 +351,19 @@ public BuildImageCmdImpl withDockerfile(File dockerfile) {

@Override
public BuildImageCmd withDockerfilePath(String dockerfilePath) {
checkNotNull(dockerfilePath, "dockerfilePath is null");
this.dockerFilePath = dockerfilePath;
this.dockerFilePath = Objects.requireNonNull(dockerfilePath, "dockerfilePath is null");
return this;
}

@Override
public BuildImageCmdImpl withTarInputStream(InputStream tarInputStream) {
checkNotNull(tarInputStream, "tarInputStream is null");
this.tarInputStream = tarInputStream;
this.tarInputStream = Objects.requireNonNull(tarInputStream, "tarInputStream is null");
return this;
}

@Override
public BuildImageCmd withBuildAuthConfigs(AuthConfigurations authConfigs) {
checkNotNull(authConfigs, "authConfig is null");
this.buildAuthConfigs = authConfigs;
this.buildAuthConfigs = Objects.requireNonNull(authConfigs, "authConfig is null");
return this;
}

Expand Down
Loading