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
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
-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
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactoryTest.java41
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/package-info.java15
5 files changed, 75 insertions, 9 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;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
index 0f445ddc91..aefebef5ee 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
@@ -22,6 +22,11 @@ Require-Bundle: org.eclipse.linuxtools.docker.ui;bundle-version="1.0.0",
org.mockito;bundle-version="1.9.5",
org.eclipse.linuxtools.docker.tests.hamcrest-wrap;bundle-version="1.2.0",
com.google.guava;bundle-version="15.0.0",
- org.eclipse.debug.core;bundle-version="3.10.0"
+ org.eclipse.debug.core;bundle-version="3.10.0",
+ org.glassfish.hk2.api;bundle-version="2.3.0",
+ com.fasterxml.jackson.core.jackson-core;bundle-version="2.5.0",
+ com.fasterxml.jackson.core.jackson-databind;bundle-version="2.5.0",
+ org.slf4j.api;bundle-version="1.7.2",
+ org.glassfish.jersey.bundles.repackaged.jersey-guava;bundle-version="2.14.0"
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactoryTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactoryTest.java
new file mode 100644
index 0000000000..ce49f35896
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactoryTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.core;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+import com.spotify.docker.client.DockerCertificateException;
+import com.spotify.docker.client.DockerClient;
+
+/**
+ * Testing the {@link DockerClientFactory}
+ */
+public class DockerClientFactoryTest {
+
+ @Test
+ public void shouldNotFailWithNullTcpHost() throws DockerCertificateException {
+ // when
+ final DockerClient client = new DockerClientFactory().getClient(null, null, null);
+ // then
+ assertThat(client).isNull();
+ }
+
+ @Test
+ public void shouldNotFailWithEmptyTcpHost() throws DockerCertificateException {
+ // when
+ final DockerClient client = new DockerClientFactory().getClient(null, "", null);
+ // then
+ assertThat(client).isNull();
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/package-info.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/package-info.java
new file mode 100644
index 0000000000..ff76e656fe
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/core/package-info.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+/**
+ *
+ */
+package org.eclipse.linuxtools.internal.docker.core; \ No newline at end of file

Back to the top