Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-01-13 17:28:51 +0000
committerJeff Johnston2016-01-20 22:40:12 +0000
commitc781ec59c97769f12529e76f724a2b730b770821 (patch)
tree9a3668a2ee724e0a8683200848ca80b783b04139 /containers/org.eclipse.linuxtools.docker.core/src/org/eclipse
parenteb1ec4580e172b3c15cb4261a707bcc248e4418e (diff)
downloadorg.eclipse.linuxtools-c781ec59c97769f12529e76f724a2b730b770821.tar.gz
org.eclipse.linuxtools-c781ec59c97769f12529e76f724a2b730b770821.tar.xz
org.eclipse.linuxtools-c781ec59c97769f12529e76f724a2b730b770821.zip
Bug 485734 - NullPointerException below DockerClientFactory.getClient
Avoid building a client when params are null or empty Change-Id: Id967ecedd7a69e0816fcc4a6a2c27599cb9efa79 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/64284 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Reviewed-on: https://git.eclipse.org/r/64739
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.core/src/org/eclipse')
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java13
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java8
2 files changed, 13 insertions, 8 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
index 04a410e581..7206a9dec8 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
@@ -41,17 +41,22 @@ public class DockerClientFactory {
*/
public DockerClient getClient(final String socketPath, final String tcpHost,
final String tcpCertPath) throws DockerCertificateException {
- if (socketPath != null) {
+ final boolean validSocketPath = socketPath != null
+ && !socketPath.isEmpty();
+ final boolean validTcpHost = tcpHost != null && !tcpHost.isEmpty();
+ final boolean validTcpCertPath = tcpCertPath != null
+ && !tcpCertPath.isEmpty();
+ if (validSocketPath) {
return DefaultDockerClient.builder().uri(socketPath).build();
- } else if (tcpCertPath != null) {
+ } else if (validTcpCertPath && validTcpHost) {
return DefaultDockerClient.builder().uri(URI.create(tcpHost))
.dockerCertificates(new DockerCertificates(
new File(tcpCertPath).toPath()))
.build();
- } else {
+ } else if (validTcpHost) {
return DefaultDockerClient.builder().uri(URI.create(tcpHost))
.build();
}
-
+ return null;
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index ed4a5ed51f..0baa460dfb 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -120,7 +120,7 @@ public class DockerConnection implements IDockerConnection, Closeable {
}
public Builder tcpHost(String tcpHost) {
- if (tcpHost != null) {
+ if (tcpHost != null && !tcpHost.isEmpty()) {
if (!tcpHost.matches("\\w+://.*")) { //$NON-NLS-1$
tcpHost = "tcp://" + tcpHost; //$NON-NLS-1$
}
@@ -281,8 +281,8 @@ public class DockerConnection implements IDockerConnection, Closeable {
@Override
public void ping() throws DockerException {
try {
- if (client != null) {
- client.ping();
+ if (this.client != null) {
+ this.client.ping();
} else {
throw new DockerException(Messages.Docker_Daemon_Ping_Failure);
}
@@ -295,7 +295,7 @@ public class DockerConnection implements IDockerConnection, Closeable {
@Override
public void close() {
synchronized (clientLock) {
- if (client != null) {
+ if (this.client != null) {
this.client.close();
this.client = null;
}

Back to the top