aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2018-08-03 15:35:16 -0400
committerJeff Johnston2018-08-03 17:30:45 -0400
commit203bc98f9c812ec0212494dd1573238a4b17d331 (patch)
treed23c5caaa86611437710ff8381e25ae43a41cbfa
parentc96ecb3c76d70ad8cf0eaf96f6d6356a0b7388aa (diff)
downloadorg.eclipse.linuxtools-203bc98f9c812ec0212494dd1573238a4b17d331.tar.gz
org.eclipse.linuxtools-203bc98f9c812ec0212494dd1573238a4b17d331.tar.xz
org.eclipse.linuxtools-203bc98f9c812ec0212494dd1573238a4b17d331.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>
-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);