Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-01-15 09:10:52 +0000
committerJeff Johnston2016-01-18 21:57:10 +0000
commit919d59c4404f788576d37a5c9375435872780c7b (patch)
tree04a9cff6ea8b3be79d3f31f2cafef611ee316f51
parent0a03290b076819c83377b6c62aa3950f2cd66e25 (diff)
downloadorg.eclipse.linuxtools-919d59c4404f788576d37a5c9375435872780c7b.tar.gz
org.eclipse.linuxtools-919d59c4404f788576d37a5c9375435872780c7b.tar.xz
org.eclipse.linuxtools-919d59c4404f788576d37a5c9375435872780c7b.zip
Bug 475331 - NullPointerException in DockerConnection.getInfo
Prevent NPE when DockerClient is null, and prevent NPE in callers that would retrieve a null value. Change-Id: I23fbdfd9f70cfdb0fc182f084377262a0eebd89d Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/64358 Tested-by: Hudson CI Reviewed-on: https://git.eclipse.org/r/64600 Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java11
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java12
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/LaunchConfigurationUtils.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ConnectionInfoPropertySection.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunResourceVolumesVariablesModel.java9
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java18
6 files changed, 41 insertions, 21 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java
index 7be3d641fb..d0511a072d 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 Red Hat.
+ * Copyright (c) 2014-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
@@ -65,7 +65,7 @@ public interface IDockerConnection {
/**
* @return the {@link IDockerImageInfo} for the {@link IDockerImage}
* identified by the given {@code id} or <code>null</code> if none
- * was found.
+ * was found or if the underlying client was not initialized
* @param id
* the {@link IDockerImage} id
*/
@@ -157,8 +157,11 @@ public interface IDockerConnection {
public void close();
/**
- * @return the {@link IDockerConnectionInfo} associated with this {@link IDockerConnection}
- * @throws DockerException if info retrieval failed
+ * @return the {@link IDockerConnectionInfo} associated with this
+ * {@link IDockerConnection} or <code>null</code> if the underlying
+ * client was not initialized.
+ * @throws DockerException
+ * if info retrieval failed
*/
public IDockerConnectionInfo getInfo() throws DockerException;
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 3978674534..e03cdc02de 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
@@ -303,9 +303,12 @@ public class DockerConnection implements IDockerConnection, Closeable {
@Override
public IDockerConnectionInfo getInfo() throws DockerException {
+ if (this.client == null) {
+ return null;
+ }
try {
- final Info info = client.info();
- final Version version = client.version();
+ final Info info = this.client.info();
+ final Version version = this.client.version();
return new DockerConnectionInfo(info, version);
} catch (com.spotify.docker.client.DockerRequestException e) {
throw new DockerException(e.message());
@@ -638,8 +641,11 @@ public class DockerConnection implements IDockerConnection, Closeable {
@Override
public IDockerImageInfo getImageInfo(String id) {
+ if (this.client == null) {
+ return null;
+ }
try {
- final ImageInfo info = client.inspectImage(id);
+ final ImageInfo info = this.client.inspectImage(id);
return new DockerImageInfo(info);
} catch (com.spotify.docker.client.DockerRequestException e) {
Activator.logErrorMessage(e.message());
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/LaunchConfigurationUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/LaunchConfigurationUtils.java
index 8257d64f1b..2b8e3c3f90 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/LaunchConfigurationUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/LaunchConfigurationUtils.java
@@ -146,8 +146,11 @@ public class LaunchConfigurationUtils {
if (hostConfig.publishAllPorts()) {
final IDockerImageInfo imageInfo = image.getConnection()
.getImageInfo(image.id());
- workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(
- imageInfo.containerConfig().exposedPorts()));
+ if (imageInfo != null) {
+ workingCopy.setAttribute(PUBLISHED_PORTS,
+ serializePortBindings(imageInfo.containerConfig()
+ .exposedPorts()));
+ }
} else {
workingCopy.setAttribute(PUBLISHED_PORTS,
serializePortBindings(hostConfig.portBindings()));
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ConnectionInfoPropertySection.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ConnectionInfoPropertySection.java
index bd154b7397..955c5a8159 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ConnectionInfoPropertySection.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ConnectionInfoPropertySection.java
@@ -66,7 +66,10 @@ public class ConnectionInfoPropertySection extends BasePropertySection {
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Loading connection info...", 1);
try {
- result.add(connection.getInfo());
+ final IDockerConnectionInfo info = connection.getInfo();
+ if (info != null) {
+ result.add(info);
+ }
} catch (DockerException e) {
Activator.log(e);
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunResourceVolumesVariablesModel.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunResourceVolumesVariablesModel.java
index cd8166d62e..467bd64505 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunResourceVolumesVariablesModel.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunResourceVolumesVariablesModel.java
@@ -197,11 +197,14 @@ public class ImageRunResourceVolumesVariablesModel
}
/**
- * @return the total memory of the Docker daemon, in MB
- * @throws DockerException
+ * @return the total memory of the Docker daemon, in MB, or <code>-1</code>
+ * if the data is not available.
*/
public int getTotalMemory() {
- return (int) (this.info.getTotalMemory() / MB);
+ if (this.info != null) {
+ return (int) (this.info.getTotalMemory() / MB);
+ }
+ return -1;
}
public boolean isEnableResourceLimitations() {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
index 78c2eeb4ff..dfe8a952d9 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
@@ -721,7 +721,6 @@ public class ImageRunSelectionPage extends WizardPage {
}
final IDockerImageInfo selectedImageInfo = getImageInfo(
selectedImage);
-
applyImageInfo(selectedImageInfo);
}
};
@@ -859,13 +858,16 @@ public class ImageRunSelectionPage extends WizardPage {
Collections.<String> emptyList());
// FIXME: handle the case where ports where added (and selected)
// by the user.
- final List<ExposedPortModel> exposedPorts = ExposedPortModel
- .fromStrings(selectedImageInfo.config().exposedPorts());
- model.setExposedPorts(exposedPorts);
- final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel
- .fromStrings(exposedPortInfos);
- this.model
- .setSelectedPorts(new HashSet<>(selectedExposedPorts));
+ if (selectedImageInfo != null) {
+ final List<ExposedPortModel> exposedPorts = ExposedPortModel
+ .fromStrings(
+ selectedImageInfo.config().exposedPorts());
+ model.setExposedPorts(exposedPorts);
+ final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel
+ .fromStrings(exposedPortInfos);
+ this.model.setSelectedPorts(
+ new HashSet<>(selectedExposedPorts));
+ }
// links
this.model.setLinks(lastLaunchConfiguration.getAttribute(LINKS,

Back to the top