Skip to content

Commit c2286ab

Browse files
committed
Improve null-safety of buildpack/spring-boot-buildpack-platform
See gh-47263
1 parent a5c8e2b commit c2286ab

File tree

9 files changed

+24
-18
lines changed

9 files changed

+24
-18
lines changed

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

Lines changed: 6 additions & 4 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.util.StringUtils;
2022

2123
/**
@@ -26,11 +28,11 @@
2628
*/
2729
public class BuilderException extends RuntimeException {
2830

29-
private final String operation;
31+
private final @Nullable String operation;
3032

3133
private final int statusCode;
3234

33-
BuilderException(String operation, int statusCode) {
35+
BuilderException(@Nullable String operation, int statusCode) {
3436
super(buildMessage(operation, statusCode));
3537
this.operation = operation;
3638
this.statusCode = statusCode;
@@ -40,7 +42,7 @@ public class BuilderException extends RuntimeException {
4042
* Return the Builder operation that failed.
4143
* @return the operation description
4244
*/
43-
public String getOperation() {
45+
public @Nullable String getOperation() {
4446
return this.operation;
4547
}
4648

@@ -52,7 +54,7 @@ public int getStatusCode() {
5254
return this.statusCode;
5355
}
5456

55-
private static String buildMessage(String operation, int statusCode) {
57+
private static String buildMessage(@Nullable String operation, int statusCode) {
5658
StringBuilder message = new StringBuilder("Builder");
5759
if (StringUtils.hasLength(operation)) {
5860
message.append(" lifecycle '").append(operation).append("'");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static BuildpackCoordinates fromBuildpackMetadata(BuildpackMetadata buildpackMet
134134
* @param version the buildpack version
135135
* @return a new {@link BuildpackCoordinates} instance
136136
*/
137-
static BuildpackCoordinates of(String id, String version) {
137+
static BuildpackCoordinates of(String id, @Nullable String version) {
138138
return new BuildpackCoordinates(id, version);
139139
}
140140

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.buildpack.platform.docker.type.Layer;
2426
import org.springframework.boot.buildpack.platform.io.Content;
2527
import org.springframework.boot.buildpack.platform.io.IOConsumer;
@@ -79,7 +81,7 @@ private void appendToOrderToml(StringBuilder builder, BuildpackCoordinates coord
7981
builder.append("\n");
8082
}
8183

82-
static Buildpacks of(List<Buildpack> buildpacks) {
84+
static Buildpacks of(@Nullable List<Buildpack> buildpacks) {
8385
return CollectionUtils.isEmpty(buildpacks) ? EMPTY : new Buildpacks(buildpacks);
8486
}
8587

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class EphemeralBuilder {
6565
* @param buildpacks an optional set of buildpacks to apply
6666
*/
6767
EphemeralBuilder(BuildOwner buildOwner, Image builderImage, ImageReference targetImage,
68-
BuilderMetadata builderMetadata, Creator creator, Map<String, String> env,
68+
BuilderMetadata builderMetadata, Creator creator, @Nullable Map<String, String> env,
6969
@Nullable Buildpacks buildpacks) {
7070
this.name = ImageReference.random("pack.local/builder/").inTaggedForm();
7171
this.buildOwner = buildOwner;
@@ -129,7 +129,7 @@ BuilderMetadata getBuilderMetadata() {
129129
* @return the ephemeral builder archive
130130
* @throws IOException on IO error
131131
*/
132-
ImageArchive getArchive(String applicationDirectory) throws IOException {
132+
ImageArchive getArchive(@Nullable String applicationDirectory) throws IOException {
133133
return ImageArchive.from(this.builderImage, (update) -> {
134134
this.archiveUpdate.accept(update);
135135
if (StringUtils.hasLength(applicationDirectory)) {

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public class ImageApi {
207207
* @return the {@link ImageApi pulled image} instance
208208
* @throws IOException on IO error
209209
*/
210-
public Image pull(ImageReference reference, ImagePlatform platform,
210+
public Image pull(ImageReference reference, @Nullable ImagePlatform platform,
211211
UpdateListener<PullImageUpdateEvent> listener) throws IOException {
212212
return pull(reference, platform, listener, null);
213213
}

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/TotalProgressBar.java

Lines changed: 3 additions & 1 deletion
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.util.StringUtils;
2325

2426
/**
@@ -62,7 +64,7 @@ public TotalProgressBar(String prefix, PrintStream out) {
6264
* @param bookend if bookends should be printed
6365
* @param out the output print stream to use
6466
*/
65-
public TotalProgressBar(String prefix, char progressChar, boolean bookend, PrintStream out) {
67+
public TotalProgressBar(@Nullable String prefix, char progressChar, boolean bookend, PrintStream out) {
6668
this.progressChar = progressChar;
6769
this.bookend = bookend;
6870
if (StringUtils.hasLength(prefix)) {

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DockerRegistryConfigAuthentication implements DockerRegistryAuthentication
4949

5050
private final BiConsumer<String, Exception> credentialHelperExceptionHandler;
5151

52-
private final Function<String, CredentialHelper> credentialHelperFactory;
52+
private final Function<String, @Nullable CredentialHelper> credentialHelperFactory;
5353

5454
private final DockerConfig dockerConfig;
5555

@@ -61,7 +61,7 @@ class DockerRegistryConfigAuthentication implements DockerRegistryAuthentication
6161

6262
DockerRegistryConfigAuthentication(@Nullable DockerRegistryAuthentication fallback,
6363
BiConsumer<String, Exception> credentialHelperExceptionHandler, Environment environment,
64-
Function<String, CredentialHelper> credentialHelperFactory) {
64+
Function<String, @Nullable CredentialHelper> credentialHelperFactory) {
6565
this.fallback = fallback;
6666
this.credentialHelperExceptionHandler = credentialHelperExceptionHandler;
6767
this.dockerConfig = DockerConfigurationMetadata.from(environment).getConfiguration();

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/KeyStoreFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private KeyStoreFactory() {
5050
* @param alias the alias to use for KeyStore entries
5151
* @return the {@code KeyStore}
5252
*/
53-
static KeyStore create(Path certPath, Path keyPath, String alias) {
53+
static KeyStore create(Path certPath, @Nullable Path keyPath, String alias) {
5454
try {
5555
KeyStore keyStore = getKeyStore();
5656
String certificateText = Files.readString(certPath);

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public class DockerEngineException extends RuntimeException {
3434

3535
private final int statusCode;
3636

37-
private final String reasonPhrase;
37+
private final @Nullable String reasonPhrase;
3838

3939
private final @Nullable Errors errors;
4040

4141
private final @Nullable Message responseMessage;
4242

43-
public DockerEngineException(String host, URI uri, int statusCode, String reasonPhrase, @Nullable Errors errors,
44-
@Nullable Message responseMessage) {
43+
public DockerEngineException(String host, URI uri, int statusCode, @Nullable String reasonPhrase,
44+
@Nullable Errors errors, @Nullable Message responseMessage) {
4545
super(buildMessage(host, uri, statusCode, reasonPhrase, errors, responseMessage));
4646
this.statusCode = statusCode;
4747
this.reasonPhrase = reasonPhrase;
@@ -61,7 +61,7 @@ public int getStatusCode() {
6161
* Return the reason phrase returned by the Docker API.
6262
* @return the reasonPhrase
6363
*/
64-
public String getReasonPhrase() {
64+
public @Nullable String getReasonPhrase() {
6565
return this.reasonPhrase;
6666
}
6767

@@ -83,7 +83,7 @@ public String getReasonPhrase() {
8383
return this.responseMessage;
8484
}
8585

86-
private static String buildMessage(String host, URI uri, int statusCode, String reasonPhrase,
86+
private static String buildMessage(String host, URI uri, int statusCode, @Nullable String reasonPhrase,
8787
@Nullable Errors errors, @Nullable Message responseMessage) {
8888
Assert.notNull(host, "'host' must not be null");
8989
Assert.notNull(uri, "'uri' must not be null");

0 commit comments

Comments
 (0)