Skip to content

Commit 94d7641

Browse files
kprokopchikbsideup
authored andcommitted
Fix NPE for GenericContainer::isRunning (#411) (#412)
* Fix NPE for GenericContainer::isRunning (#411) * Add test for GenericContainer::isRunning (#411) * Fix not stopped container in test (#411) * Added comment to CHANGELOG.md (#411)
1 parent 99b1084 commit 94d7641

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
### Fixed
66
- Worked around incompatibility between Netty's Unix socket support and OS X 10.11. Reinstated use of TCP-Unix Socket proxy when running on OS X prior to v10.12. (Fixes #402)
77
- Changed to use version 2.0 of the Visible Assertions library for startup pre-flight checks. This no longer has a dependency on Jansi, and is intended to resolve a JVM crash issue apparently caused by native lib version conflicts (#395). Please note that the newer ANSI code is less mature and thus has had less testing, particularly in interesting terminal environments such as Windows. If issues are encountered, coloured assertion output may be disabled by setting the system property `visibleassertions.ansi.enabled` to `true`.
8+
- Fixed NullPointerException when calling GenericContainer#isRunning on not started container (#411)
89

910
### Changed
1011
- Removed Guava usage from `jdbc` module (#401)

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public String getIpAddress() {
723723
@Override
724724
public Boolean isRunning() {
725725
try {
726-
return dockerClient.inspectContainerCmd(containerId).exec().getState().getRunning();
726+
return containerId != null && dockerClient.inspectContainerCmd(containerId).exec().getState().getRunning();
727727
} catch (DockerException e) {
728728
return false;
729729
}

core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ public static void setupContent() throws FileNotFoundException {
144144
// assertTrue("The list contains an item that was put in (redis is working!)", testList2.contains("baz"));
145145
// }
146146

147+
@Test
148+
public void testIsRunning() {
149+
try (GenericContainer container = new GenericContainer()) {
150+
assertFalse("Container is not started and not running", container.isRunning());
151+
container.start();
152+
assertTrue("Container is started and running", container.isRunning());
153+
}
154+
}
155+
147156
@Test
148157
public void simpleRabbitMqTest() throws IOException, TimeoutException {
149158
ConnectionFactory factory = new ConnectionFactory();

0 commit comments

Comments
 (0)