Skip to content

Commit a6b4400

Browse files
committed
Improve null-safety of core/spring-boot-docker-compose
See gh-46926
1 parent 8c0018d commit a6b4400

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliInspectResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Phillip Webb
3434
*/
3535
record DockerCliInspectResponse(String id, DockerCliInspectResponse.Config config,
36-
DockerCliInspectResponse.NetworkSettings networkSettings,
36+
DockerCliInspectResponse.@Nullable NetworkSettings networkSettings,
3737
DockerCliInspectResponse.@Nullable HostConfig hostConfig) {
3838

3939
/**

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerEnv.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class DockerEnv {
4040
* Create a new {@link DockerEnv} instance.
4141
* @param env a list of env entries in the form {@code name=value} or {@code name}.
4242
*/
43-
DockerEnv(List<String> env) {
43+
DockerEnv(@Nullable List<String> env) {
4444
this.map = parse(env);
4545
}
4646

47-
private Map<String, @Nullable String> parse(List<String> env) {
47+
private Map<String, @Nullable String> parse(@Nullable List<String> env) {
4848
if (CollectionUtils.isEmpty(env)) {
4949
return Collections.emptyMap();
5050
}

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerHost.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static DockerHost get(@Nullable String host, Supplier<List<DockerCliContextRespo
8383
* {@link DockerCliContextResponse}
8484
* @return a new docker host instance
8585
*/
86-
static DockerHost get(@Nullable String host, Function<String, String> systemEnv,
86+
static DockerHost get(@Nullable String host, Function<String, @Nullable String> systemEnv,
8787
Supplier<List<DockerCliContextResponse>> contextsSupplier) {
8888
host = (StringUtils.hasText(host)) ? host : fromServicesHostEnv(systemEnv);
8989
host = (StringUtils.hasText(host)) ? host : fromDockerHostEnv(systemEnv);
@@ -92,11 +92,11 @@ static DockerHost get(@Nullable String host, Function<String, String> systemEnv,
9292
return new DockerHost(host);
9393
}
9494

95-
private static String fromServicesHostEnv(Function<String, String> systemEnv) {
95+
private static @Nullable String fromServicesHostEnv(Function<String, @Nullable String> systemEnv) {
9696
return systemEnv.apply("SERVICES_HOST");
9797
}
9898

99-
private static @Nullable String fromDockerHostEnv(Function<String, String> systemEnv) {
99+
private static @Nullable String fromDockerHostEnv(Function<String, @Nullable String> systemEnv) {
100100
return fromEndpoint(systemEnv.apply("DOCKER_HOST"));
101101
}
102102

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import org.springframework.aot.AotDetector;
2929
import org.springframework.boot.SpringApplicationShutdownHandlers;
30-
import org.springframework.boot.context.properties.bind.Binder;
3130
import org.springframework.boot.docker.compose.core.DockerCompose;
3231
import org.springframework.boot.docker.compose.core.DockerComposeFile;
3332
import org.springframework.boot.docker.compose.core.RunningService;
@@ -74,14 +73,14 @@ class DockerComposeLifecycleManager {
7473

7574
private final ServiceReadinessChecks serviceReadinessChecks;
7675

77-
DockerComposeLifecycleManager(ApplicationContext applicationContext, Binder binder,
76+
DockerComposeLifecycleManager(ApplicationContext applicationContext,
7877
SpringApplicationShutdownHandlers shutdownHandlers, DockerComposeProperties properties,
7978
Set<ApplicationListener<?>> eventListeners) {
80-
this(null, applicationContext, binder, shutdownHandlers, properties, eventListeners,
81-
new DockerComposeSkipCheck(), null);
79+
this(null, applicationContext, shutdownHandlers, properties, eventListeners, new DockerComposeSkipCheck(),
80+
null);
8281
}
8382

84-
DockerComposeLifecycleManager(@Nullable File workingDirectory, ApplicationContext applicationContext, Binder binder,
83+
DockerComposeLifecycleManager(@Nullable File workingDirectory, ApplicationContext applicationContext,
8584
SpringApplicationShutdownHandlers shutdownHandlers, DockerComposeProperties properties,
8685
Set<ApplicationListener<?>> eventListeners, DockerComposeSkipCheck skipCheck,
8786
@Nullable ServiceReadinessChecks serviceReadinessChecks) {

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public void onApplicationEvent(ApplicationPreparedEvent event) {
5656
protected DockerComposeLifecycleManager createDockerComposeLifecycleManager(
5757
ConfigurableApplicationContext applicationContext, Binder binder, DockerComposeProperties properties,
5858
Set<ApplicationListener<?>> eventListeners) {
59-
return new DockerComposeLifecycleManager(applicationContext, binder, this.shutdownHandlers, properties,
60-
eventListeners);
59+
return new DockerComposeLifecycleManager(applicationContext, this.shutdownHandlers, properties, eventListeners);
6160
}
6261

6362
}

core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void setup() throws IOException {
109109
this.eventListeners = new LinkedHashSet<>();
110110
this.skipCheck = mock(DockerComposeSkipCheck.class);
111111
this.serviceReadinessChecks = mock(ServiceReadinessChecks.class);
112-
this.lifecycleManager = new TestDockerComposeLifecycleManager(workingDirectory, this.applicationContext, binder,
112+
this.lifecycleManager = new TestDockerComposeLifecycleManager(workingDirectory, this.applicationContext,
113113
this.shutdownHandlers, this.properties, this.eventListeners, this.skipCheck,
114114
this.serviceReadinessChecks);
115115
}
@@ -152,15 +152,15 @@ void startWhenUsingAotArtifactsDoesNotStart() {
152152
@Test
153153
void startWhenComposeFileNotFoundThrowsException() {
154154
DockerComposeLifecycleManager manager = new DockerComposeLifecycleManager(new File("."),
155-
this.applicationContext, null, this.shutdownHandlers, this.properties, this.eventListeners,
156-
this.skipCheck, this.serviceReadinessChecks);
155+
this.applicationContext, this.shutdownHandlers, this.properties, this.eventListeners, this.skipCheck,
156+
this.serviceReadinessChecks);
157157
assertThatIllegalStateException().isThrownBy(manager::start)
158158
.withMessageContaining(Paths.get(".").toAbsolutePath().toString());
159159
}
160160

161161
@Test
162162
void startWhenComposeFileNotFoundAndWorkingDirectoryNullThrowsException() {
163-
DockerComposeLifecycleManager manager = new DockerComposeLifecycleManager(null, this.applicationContext, null,
163+
DockerComposeLifecycleManager manager = new DockerComposeLifecycleManager(null, this.applicationContext,
164164
this.shutdownHandlers, this.properties, this.eventListeners, this.skipCheck,
165165
this.serviceReadinessChecks);
166166
assertThatIllegalStateException().isThrownBy(manager::start)
@@ -516,11 +516,11 @@ DockerComposeServicesReadyEvent getEvent() {
516516
*/
517517
class TestDockerComposeLifecycleManager extends DockerComposeLifecycleManager {
518518

519-
TestDockerComposeLifecycleManager(File workingDirectory, ApplicationContext applicationContext, Binder binder,
519+
TestDockerComposeLifecycleManager(File workingDirectory, ApplicationContext applicationContext,
520520
SpringApplicationShutdownHandlers shutdownHandlers, DockerComposeProperties properties,
521521
Set<ApplicationListener<?>> eventListeners, DockerComposeSkipCheck skipCheck,
522522
ServiceReadinessChecks serviceReadinessChecks) {
523-
super(workingDirectory, applicationContext, binder, shutdownHandlers, properties, eventListeners, skipCheck,
523+
super(workingDirectory, applicationContext, shutdownHandlers, properties, eventListeners, skipCheck,
524524
serviceReadinessChecks);
525525
}
526526

0 commit comments

Comments
 (0)