Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing null check for JDBC init script #9118

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -361,7 +362,10 @@ protected void optionallyMapResourceParameterAsVolume(
* Load init script content and apply it to the database if initScriptPath is set
*/
protected void runInitScriptIfRequired() {
initScriptPaths.forEach(path -> ScriptUtils.runInitScript(getDatabaseDelegate(), path));
initScriptPaths
.stream()
.filter(Objects::nonNull)
.forEach(path -> ScriptUtils.runInitScript(getDatabaseDelegate(), path));
}

public void setParameters(Map<String, String> parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.logging.LogManager;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;

public class SimplePostgreSQLTest extends AbstractContainerDatabaseTest {
static {
Expand Down Expand Up @@ -59,6 +60,16 @@ public void testUnsetCommand() throws SQLException {
}
}

@Test
public void testMissingInitScript() {
try (
PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(PostgreSQLTestImages.POSTGRES_TEST_IMAGE)
.withInitScript(null)
) {
assertThatNoException().isThrownBy(postgres::start);
}
}

@Test
public void testExplicitInitScript() throws SQLException {
try (
Expand Down
Loading