Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2018-08-03 15:35:16 -0400
committerJeff Johnston2018-08-07 11:31:52 -0400
commit71c2af0dc3a441e4b3bcb48b5bf9ec8692385777 (patch)
treea37acddc5d009c75d5c3bd1cabc2866468c2bae7
parent00df955beb996c73ac3ca5d7df2a7f119bd2873e (diff)
downloadorg.eclipse.linuxtools-71c2af0dc3a441e4b3bcb48b5bf9ec8692385777.tar.gz
org.eclipse.linuxtools-71c2af0dc3a441e4b3bcb48b5bf9ec8692385777.tar.xz
org.eclipse.linuxtools-71c2af0dc3a441e4b3bcb48b5bf9ec8692385777.zip
Bug 537681 - NullPointerException in RunConsole.lambda$1
- in RunConsole attachToTerminal and attachToConsole, the code uses the Docker Connection to get the DockerContainerInfo and from there, the state of the container - there has been history of the state not being reported immediately and it is possible that the container info is coming back null so added checks have been added so if it does, an NPE will not occur and a few more attempts will be made to get the container info Change-Id: I165accbf6270dca1f89e60209875ed43a6730f6c Reviewed-on: https://git.eclipse.org/r/127047 Tested-by: CI Bot Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit 203bc98f9c812ec0212494dd1573238a4b17d331) Reviewed-on: https://git.eclipse.org/r/127054
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java68
1 files changed, 51 insertions, 17 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
index 98176a768f..36ea489caf 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/consoles/RunConsole.java
@@ -19,6 +19,7 @@ import java.io.OutputStream;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerContainerInfo;
import org.eclipse.linuxtools.docker.core.IDockerContainerState;
import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
@@ -150,19 +151,36 @@ public class RunConsole extends IOConsole {
try {
DockerConnection conn = (DockerConnection) connection;
if (conn.getContainerInfo(containerId).config().openStdin()) {
- IDockerContainerState state = conn
- .getContainerInfo(containerId).state();
+ IDockerContainerInfo info = conn.getContainerInfo(containerId);
+ IDockerContainerState state = null;
+ if (info != null) {
+ state = info.state();
+ }
+ int sleepCounter = 0;
do {
- if (!state.running() && (state.finishDate() == null
+ if (state == null || (!state.running() && (state.finishDate() == null
|| state.finishDate()
- .before(state.startDate()))) {
+ .before(state.startDate())))) {
Thread.sleep(300);
+ ++sleepCounter;
+ }
+ state = null;
+ info = conn.getContainerInfo(containerId);
+ if (info != null) {
+ state = info.state();
+ } else {
+ if (sleepCounter > 2) {
+ break;
+ }
}
- state = conn.getContainerInfo(containerId).state();
- } while (!state.running() && (state.finishDate() == null
- || state.finishDate().before(state.startDate())));
+ } while (state == null || (!state.running()
+ && (state.finishDate() == null || state.finishDate().before(state.startDate()))));
Thread.sleep(300);
- state = conn.getContainerInfo(containerId).state();
+ info = conn.getContainerInfo(containerId);
+ if (info == null) {
+ return;
+ }
+ state = info.state();
if (state.running()) {
conn.attachCommand(containerId, in, null);
}
@@ -180,22 +198,37 @@ public class RunConsole extends IOConsole {
Thread t = new Thread(() -> {
try {
DockerConnection conn = (DockerConnection) connection;
- IDockerContainerState state = conn.getContainerInfo(containerId)
- .state();
+ IDockerContainerInfo info = conn.getContainerInfo(containerId);
+ IDockerContainerState state = null;
+ if (info != null) {
+ state = info.state();
+ }
+ int sleepCounter = 0;
do {
- if (!state.running() && (state.finishDate() == null
- || state.finishDate().before(state.startDate()))) {
+ if (state == null || (!state.running()
+ && (state.finishDate() == null || state.finishDate().before(state.startDate())))) {
Thread.sleep(300);
+ ++sleepCounter;
+ }
+ state = null;
+ info = conn.getContainerInfo(containerId);
+ if (info != null) {
+ state = info.state();
+ } else if (sleepCounter > 2) {
+ break;
}
- state = conn.getContainerInfo(containerId).state();
- } while (!state.running() && (state.finishDate() == null
- || state.finishDate().before(state.startDate())));
+ } while (state == null || (!state.running()
+ && (state.finishDate() == null || state.finishDate().before(state.startDate()))));
// Pause as there appears to be some timing issue with regards
// to the Container saying it is running, but an exception
// thrown when we try and attach.
Thread.sleep(300);
- state = conn.getContainerInfo(containerId).state();
- if (state.running()) {
+ state = null;
+ info = conn.getContainerInfo(containerId);
+ if (info != null) {
+ state = info.state();
+ }
+ if (state != null && state.running()) {
conn.attachCommand(containerId, null, out);
} else {
// notify any console listener that there is no more output
@@ -203,6 +236,7 @@ public class RunConsole extends IOConsole {
if (out != null) {
out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
}
+ return;
}
} catch (Exception e) {
Activator.log(e);

Back to the top