From c55d9aba4cc53f2608b6158418d61a5d78cd49b9 Mon Sep 17 00:00:00 2001 From: Richard North Date: Sun, 23 Sep 2018 19:53:48 +0100 Subject: [PATCH 1/2] Guard against potential NPE if startup fails before container creation --- .../containers/GenericContainer.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 0c4c2dd5a6a..32cae84951a 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -296,18 +296,20 @@ private void tryStart(Profiler profiler) { } catch (Exception e) { logger().error("Could not start container", e); - // Log output if startup failed, either due to a container failure or exception (including timeout) - logger().error("Container log output (if any) will follow:"); - FrameConsumerResultCallback resultCallback = new FrameConsumerResultCallback(); - resultCallback.addConsumer(STDOUT, new Slf4jLogConsumer(logger())); - resultCallback.addConsumer(STDERR, new Slf4jLogConsumer(logger())); - dockerClient.logContainerCmd(containerId).withStdOut(true).withStdErr(true).exec(resultCallback); - - // Try to ensure that container log output is shown before proceeding - try { - resultCallback.getCompletionLatch().await(1, TimeUnit.MINUTES); - } catch (InterruptedException ignored) { - // Cannot do anything at this point + if (containerId != null) { + // Log output if startup failed, either due to a container failure or exception (including timeout) + logger().error("Container log output (if any) will follow:"); + FrameConsumerResultCallback resultCallback = new FrameConsumerResultCallback(); + resultCallback.addConsumer(STDOUT, new Slf4jLogConsumer(logger())); + resultCallback.addConsumer(STDERR, new Slf4jLogConsumer(logger())); + dockerClient.logContainerCmd(containerId).withStdOut(true).withStdErr(true).exec(resultCallback); + + // Try to ensure that container log output is shown before proceeding + try { + resultCallback.getCompletionLatch().await(1, TimeUnit.MINUTES); + } catch (InterruptedException ignored) { + // Cannot do anything at this point + } } throw new ContainerLaunchException("Could not create/start container", e); From 585cd6831dd0225dd5ada7abb390a29ecca1b610 Mon Sep 17 00:00:00 2001 From: Richard North Date: Sun, 23 Sep 2018 20:24:56 +0100 Subject: [PATCH 2/2] Empty commit to trigger build