Skip to content

Commit 2449769

Browse files
committed
Add nullability annotations to buildpack/spring-boot-buildpack-platform
See gh-46587
1 parent 0c572ed commit 2449769

File tree

80 files changed

+595
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+595
-313
lines changed

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/AbstractBuildLog.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.List;
2020
import java.util.function.Consumer;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.buildpack.platform.docker.LogUpdateEvent;
2325
import org.springframework.boot.buildpack.platform.docker.TotalProgressEvent;
2426
import org.springframework.boot.buildpack.platform.docker.type.Binding;
@@ -45,7 +47,7 @@ public void start(BuildRequest request) {
4547
}
4648

4749
@Override
48-
public Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, ImagePlatform platform,
50+
public Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, @Nullable ImagePlatform platform,
4951
ImageType imageType) {
5052
return (platform != null)
5153
? getProgressConsumer(" > Pulling %s '%s' for platform '%s'".formatted(imageType.getDescription(),
@@ -109,7 +111,7 @@ public void taggedImage(ImageReference tag) {
109111
}
110112

111113
@Override
112-
public void failedCleaningWorkDir(Cache cache, Exception exception) {
114+
public void failedCleaningWorkDir(Cache cache, @Nullable Exception exception) {
113115
StringBuilder message = new StringBuilder("Warning: Working location " + cache + " could not be cleaned");
114116
if (exception != null) {
115117
message.append(": ").append(exception.getMessage());

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/ApiVersions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Arrays;
2020
import java.util.stream.IntStream;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.buildpack.platform.docker.type.ApiVersion;
2325
import org.springframework.util.StringUtils;
2426

@@ -62,7 +64,7 @@ ApiVersion findLatestSupported(String... others) {
6264
}
6365

6466
@Override
65-
public boolean equals(Object obj) {
67+
public boolean equals(@Nullable Object obj) {
6668
if (this == obj) {
6769
return true;
6870
}

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildLog.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.PrintStream;
2020
import java.util.function.Consumer;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.buildpack.platform.docker.LogUpdateEvent;
2325
import org.springframework.boot.buildpack.platform.docker.TotalProgressEvent;
2426
import org.springframework.boot.buildpack.platform.docker.type.Binding;
@@ -52,7 +54,7 @@ public interface BuildLog {
5254
* @param imageType the image type
5355
* @return a consumer for progress update events
5456
*/
55-
Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, ImagePlatform platform,
57+
Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, @Nullable ImagePlatform platform,
5658
ImageType imageType);
5759

5860
/**
@@ -124,7 +126,7 @@ Consumer<TotalProgressEvent> pullingImage(ImageReference imageReference, ImagePl
124126
* @param exception any exception that caused the failure
125127
* @since 3.2.6
126128
*/
127-
void failedCleaningWorkDir(Cache cache, Exception exception);
129+
void failedCleaningWorkDir(Cache cache, @Nullable Exception exception);
128130

129131
/**
130132
* Log that a binding with a sensitive target has been detected.

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildRequest.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Map;
2727
import java.util.function.Function;
2828

29+
import org.jspecify.annotations.Nullable;
30+
2931
import org.springframework.boot.buildpack.platform.docker.type.Binding;
3032
import org.springframework.boot.buildpack.platform.docker.type.ImagePlatform;
3133
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
@@ -69,9 +71,9 @@ public class BuildRequest {
6971

7072
private final ImageReference builder;
7173

72-
private final Boolean trustBuilder;
74+
private final @Nullable Boolean trustBuilder;
7375

74-
private final ImageReference runImage;
76+
private final @Nullable ImageReference runImage;
7577

7678
private final Creator creator;
7779

@@ -89,23 +91,23 @@ public class BuildRequest {
8991

9092
private final List<Binding> bindings;
9193

92-
private final String network;
94+
private final @Nullable String network;
9395

9496
private final List<ImageReference> tags;
9597

96-
private final Cache buildWorkspace;
98+
private final @Nullable Cache buildWorkspace;
9799

98-
private final Cache buildCache;
100+
private final @Nullable Cache buildCache;
99101

100-
private final Cache launchCache;
102+
private final @Nullable Cache launchCache;
101103

102-
private final Instant createdDate;
104+
private final @Nullable Instant createdDate;
103105

104-
private final String applicationDirectory;
106+
private final @Nullable String applicationDirectory;
105107

106-
private final List<String> securityOptions;
108+
private final @Nullable List<String> securityOptions;
107109

108-
private final ImagePlatform platform;
110+
private final @Nullable ImagePlatform platform;
109111

110112
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent) {
111113
Assert.notNull(name, "'name' must not be null");
@@ -135,11 +137,12 @@ public class BuildRequest {
135137
}
136138

137139
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent, ImageReference builder,
138-
Boolean trustBuilder, ImageReference runImage, Creator creator, Map<String, String> env, boolean cleanCache,
139-
boolean verboseLogging, PullPolicy pullPolicy, boolean publish, List<BuildpackReference> buildpacks,
140-
List<Binding> bindings, String network, List<ImageReference> tags, Cache buildWorkspace, Cache buildCache,
141-
Cache launchCache, Instant createdDate, String applicationDirectory, List<String> securityOptions,
142-
ImagePlatform platform) {
140+
@Nullable Boolean trustBuilder, @Nullable ImageReference runImage, Creator creator, Map<String, String> env,
141+
boolean cleanCache, boolean verboseLogging, PullPolicy pullPolicy, boolean publish,
142+
List<BuildpackReference> buildpacks, List<Binding> bindings, @Nullable String network,
143+
List<ImageReference> tags, @Nullable Cache buildWorkspace, @Nullable Cache buildCache,
144+
@Nullable Cache launchCache, @Nullable Instant createdDate, @Nullable String applicationDirectory,
145+
@Nullable List<String> securityOptions, @Nullable ImagePlatform platform) {
143146
this.name = name;
144147
this.applicationContent = applicationContent;
145148
this.builder = builder;
@@ -538,7 +541,7 @@ private boolean isBuilderKnownAndTrusted() {
538541
* Return the run image that should be used, if provided.
539542
* @return the run image
540543
*/
541-
public ImageReference getRunImage() {
544+
public @Nullable ImageReference getRunImage() {
542545
return this.runImage;
543546
}
544547

@@ -612,7 +615,7 @@ public List<Binding> getBindings() {
612615
* @return the network
613616
* @since 2.6.0
614617
*/
615-
public String getNetwork() {
618+
public @Nullable String getNetwork() {
616619
return this.network;
617620
}
618621

@@ -629,39 +632,39 @@ public List<ImageReference> getTags() {
629632
* @return the build workspace or {@code null}
630633
* @since 3.2.0
631634
*/
632-
public Cache getBuildWorkspace() {
635+
public @Nullable Cache getBuildWorkspace() {
633636
return this.buildWorkspace;
634637
}
635638

636639
/**
637640
* Return the custom build cache that should be used by the lifecycle.
638641
* @return the build cache
639642
*/
640-
public Cache getBuildCache() {
643+
public @Nullable Cache getBuildCache() {
641644
return this.buildCache;
642645
}
643646

644647
/**
645648
* Return the custom launch cache that should be used by the lifecycle.
646649
* @return the launch cache
647650
*/
648-
public Cache getLaunchCache() {
651+
public @Nullable Cache getLaunchCache() {
649652
return this.launchCache;
650653
}
651654

652655
/**
653656
* Return the custom created date that should be used by the lifecycle.
654657
* @return the created date
655658
*/
656-
public Instant getCreatedDate() {
659+
public @Nullable Instant getCreatedDate() {
657660
return this.createdDate;
658661
}
659662

660663
/**
661664
* Return the application directory that should be used by the lifecycle.
662665
* @return the application directory
663666
*/
664-
public String getApplicationDirectory() {
667+
public @Nullable String getApplicationDirectory() {
665668
return this.applicationDirectory;
666669
}
667670

@@ -670,7 +673,7 @@ public String getApplicationDirectory() {
670673
* @return the security options or {@code null}
671674
* @since 3.2.0
672675
*/
673-
public List<String> getSecurityOptions() {
676+
public @Nullable List<String> getSecurityOptions() {
674677
return this.securityOptions;
675678
}
676679

@@ -679,7 +682,7 @@ public List<String> getSecurityOptions() {
679682
* @return the platform or {@code null}
680683
* @since 3.4.0
681684
*/
682-
public ImagePlatform getImagePlatform() {
685+
public @Nullable ImagePlatform getImagePlatform() {
683686
return this.platform;
684687
}
685688

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.List;
2121
import java.util.function.Consumer;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.buildpack.platform.docker.DockerApi;
2426
import org.springframework.boot.buildpack.platform.docker.DockerLog;
2527
import org.springframework.boot.buildpack.platform.docker.TotalProgressEvent;
@@ -86,12 +88,12 @@ public Builder(BuildLog log) {
8688
* @param dockerConfiguration the docker configuration
8789
* @since 3.5.0
8890
*/
89-
public Builder(BuildLog log, BuilderDockerConfiguration dockerConfiguration) {
91+
public Builder(BuildLog log, @Nullable BuilderDockerConfiguration dockerConfiguration) {
9092
this(log, new DockerApi((dockerConfiguration != null) ? dockerConfiguration.connection() : null,
9193
BuildLogAdapter.get(log)), dockerConfiguration);
9294
}
9395

94-
Builder(BuildLog log, DockerApi docker, BuilderDockerConfiguration dockerConfiguration) {
96+
Builder(BuildLog log, DockerApi docker, @Nullable BuilderDockerConfiguration dockerConfiguration) {
9597
Assert.notNull(log, "'log' must not be null");
9698
this.log = log;
9799
this.docker = docker;
@@ -109,6 +111,7 @@ public void build(BuildRequest request) throws DockerEngineException, IOExceptio
109111
Image builderImage = imageFetcher.fetchImage(ImageType.BUILDER, request.getBuilder());
110112
BuilderMetadata builderMetadata = BuilderMetadata.fromImage(builderImage);
111113
request = withRunImageIfNeeded(request, builderMetadata);
114+
Assert.state(request.getRunImage() != null, "'request.getRunImage()' must not be null");
112115
Image runImage = imageFetcher.fetchImage(ImageType.RUNNER, request.getRunImage());
113116
assertStackIdsMatch(runImage, builderImage);
114117
BuildOwner buildOwner = BuildOwner.fromEnv(builderImage.getConfig().getEnv());
@@ -181,7 +184,7 @@ private void executeLifecycle(EphemeralBuilder builder, Lifecycle lifecycle) thr
181184
}
182185
}
183186

184-
private ResolvedDockerHost getDockerHost() {
187+
private @Nullable ResolvedDockerHost getDockerHost() {
185188
boolean bindToBuilder = this.dockerConfiguration.bindHostToBuilder();
186189
return (bindToBuilder) ? ResolvedDockerHost.from(this.dockerConfiguration.connection()) : null;
187190
}
@@ -208,7 +211,8 @@ private void pushImage(ImageReference reference) throws IOException {
208211
this.log.pushedImage(reference);
209212
}
210213

211-
private static String authHeader(DockerRegistryAuthentication authentication, ImageReference reference) {
214+
private static @Nullable String authHeader(@Nullable DockerRegistryAuthentication authentication,
215+
ImageReference reference) {
212216
return (authentication != null) ? authentication.getAuthHeader(reference) : null;
213217
}
214218

@@ -217,14 +221,14 @@ private static String authHeader(DockerRegistryAuthentication authentication, Im
217221
*/
218222
private class ImageFetcher {
219223

220-
private final DockerRegistryAuthentication registryAuthentication;
224+
private final @Nullable DockerRegistryAuthentication registryAuthentication;
221225

222226
private final PullPolicy pullPolicy;
223227

224-
private ImagePlatform defaultPlatform;
228+
private @Nullable ImagePlatform defaultPlatform;
225229

226-
ImageFetcher(DockerRegistryAuthentication registryAuthentication, PullPolicy pullPolicy,
227-
ImagePlatform platform) {
230+
ImageFetcher(@Nullable DockerRegistryAuthentication registryAuthentication, PullPolicy pullPolicy,
231+
@Nullable ImagePlatform platform) {
228232
this.registryAuthentication = registryAuthentication;
229233
this.pullPolicy = pullPolicy;
230234
this.defaultPlatform = platform;

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpack.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.buildpack.platform.docker.type.Layer;
2224
import org.springframework.boot.buildpack.platform.io.IOConsumer;
2325
import org.springframework.util.Assert;
@@ -59,18 +61,24 @@ public void apply(IOConsumer<Layer> layers) throws IOException {
5961
* @param reference the buildpack reference
6062
* @return the resolved {@link Buildpack} or {@code null}
6163
*/
62-
static Buildpack resolve(BuildpackResolverContext context, BuildpackReference reference) {
64+
static @Nullable Buildpack resolve(BuildpackResolverContext context, BuildpackReference reference) {
6365
boolean unambiguous = reference.hasPrefix(PREFIX);
6466
BuilderReference builderReference = BuilderReference
65-
.of(unambiguous ? reference.getSubReference(PREFIX) : reference.toString());
67+
.of(unambiguous ? getSubReference(reference) : reference.toString());
6668
BuildpackMetadata buildpackMetadata = findBuildpackMetadata(context, builderReference);
6769
if (unambiguous) {
6870
Assert.state(buildpackMetadata != null, () -> "Buildpack '" + reference + "' not found in builder");
6971
}
7072
return (buildpackMetadata != null) ? new BuilderBuildpack(buildpackMetadata) : null;
7173
}
7274

73-
private static BuildpackMetadata findBuildpackMetadata(BuildpackResolverContext context,
75+
private static String getSubReference(BuildpackReference reference) {
76+
String result = reference.getSubReference(PREFIX);
77+
Assert.state(result != null, "'result' must not be null");
78+
return result;
79+
}
80+
81+
private static @Nullable BuildpackMetadata findBuildpackMetadata(BuildpackResolverContext context,
7482
BuilderReference builderReference) {
7583
for (BuildpackMetadata candidate : context.getBuildpackMetadata()) {
7684
if (builderReference.matches(candidate)) {
@@ -87,9 +95,9 @@ static class BuilderReference {
8795

8896
private final String id;
8997

90-
private final String version;
98+
private final @Nullable String version;
9199

92-
BuilderReference(String id, String version) {
100+
BuilderReference(String id, @Nullable String version) {
93101
this.id = id;
94102
this.version = version;
95103
}

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderDockerConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.buildpack.platform.build;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConnectionConfiguration;
2022
import org.springframework.boot.buildpack.platform.docker.configuration.DockerRegistryAuthentication;
2123

@@ -32,9 +34,9 @@
3234
* @author Scott Frederick
3335
* @since 3.5.0
3436
*/
35-
public record BuilderDockerConfiguration(DockerConnectionConfiguration connection, boolean bindHostToBuilder,
36-
DockerRegistryAuthentication builderRegistryAuthentication,
37-
DockerRegistryAuthentication publishRegistryAuthentication) {
37+
public record BuilderDockerConfiguration(@Nullable DockerConnectionConfiguration connection, boolean bindHostToBuilder,
38+
@Nullable DockerRegistryAuthentication builderRegistryAuthentication,
39+
@Nullable DockerRegistryAuthentication publishRegistryAuthentication) {
3840

3941
public BuilderDockerConfiguration() {
4042
this(null, false, null, null);

0 commit comments

Comments
 (0)