Improve null-safety of build-plugin/spring-boot-maven-plugin

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-16 14:07:15 +02:00
parent ef6fa41dd1
commit c2548e204e
4 changed files with 11 additions and 6 deletions
@@ -79,7 +79,7 @@ public class ArtifactsLibraries implements Libraries {
* @since 2.4.0
*/
public ArtifactsLibraries(Set<Artifact> artifacts, Collection<MavenProject> localProjects,
Collection<Dependency> unpacks, Log log) {
@Nullable Collection<Dependency> unpacks, Log log) {
this(artifacts, artifacts, localProjects, unpacks, log);
}
@@ -33,6 +33,8 @@ import java.util.function.UnaryOperator;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -125,12 +127,12 @@ final class ClassPath {
* @param urls the class path URLs
* @return a new {@link ClassPath} instance
*/
static ClassPath of(UnaryOperator<String> getSystemProperty, List<URL> urls) {
static ClassPath of(UnaryOperator<@Nullable String> getSystemProperty, List<URL> urls) {
boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty);
return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR));
}
private static boolean isWindows(UnaryOperator<String> getSystemProperty) {
private static boolean isWindows(UnaryOperator<@Nullable String> getSystemProperty) {
String os = getSystemProperty.apply("os.name");
return StringUtils.hasText(os) && os.toLowerCase(Locale.ROOT).contains("win");
}
@@ -51,7 +51,8 @@ final class CommandLineBuilder {
return new CommandLineBuilder(mainClass);
}
CommandLineBuilder withJvmArguments(String... jvmArguments) {
// Do not use String @Nullable ... jvmArguments, Maven can't deal with that
CommandLineBuilder withJvmArguments(@Nullable String... jvmArguments) {
if (jvmArguments != null) {
this.options.addAll(Arrays.stream(jvmArguments).filter(Objects::nonNull).toList());
}
@@ -75,7 +76,8 @@ final class CommandLineBuilder {
return this;
}
CommandLineBuilder withArguments(String... arguments) {
// Do not use String @Nullable ... arguments, Maven can't deal with that
CommandLineBuilder withArguments(@Nullable String... arguments) {
if (arguments != null) {
this.arguments.addAll(Arrays.stream(arguments).filter(Objects::nonNull).toList());
}
@@ -230,7 +230,8 @@ public class Docker {
public DockerRegistry() {
}
public DockerRegistry(String username, String password, String url, String email) {
public DockerRegistry(@Nullable String username, @Nullable String password, @Nullable String url,
@Nullable String email) {
this.username = username;
this.password = password;
this.url = url;