Improve null-safety of cli/spring-boot-cli

See gh-46926
This commit is contained in:
Moritz Halbritter
2025-08-26 14:22:53 +02:00
parent ca7e025dfd
commit a0a785ec92
3 changed files with 13 additions and 6 deletions
@@ -31,6 +31,7 @@ import org.springframework.boot.cli.command.core.HintCommand;
import org.springframework.boot.cli.command.core.VersionCommand;
import org.springframework.boot.cli.command.shell.ShellCommand;
import org.springframework.boot.loader.tools.LogbackInitializer;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.SystemPropertyUtils;
@@ -84,7 +85,9 @@ public final class SpringCli {
String home = SystemPropertyUtils.resolvePlaceholders("${spring.home:${SPRING_HOME:.}}");
File extDirectory = new File(new File(home, "lib"), "ext");
if (extDirectory.isDirectory()) {
for (File file : extDirectory.listFiles()) {
File[] files = extDirectory.listFiles();
Assert.state(files != null, "'files' must not be null");
for (File file : files) {
if (file.getName().endsWith(".jar")) {
try {
urls.add(file.toURI().toURL());
@@ -98,7 +98,9 @@ class ProjectGenerator {
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(entity.getContent()))) {
byte[] content = entity.getContent();
Assert.state(content != null, "'content' must not be null");
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(content))) {
extractFromStream(zipStream, overwrite, outputDirectory);
fixExecutableFlag(outputDirectory, "mvnw");
fixExecutableFlag(outputDirectory, "gradlew");
@@ -52,8 +52,9 @@ class RunProcessCommand extends AbstractCommand {
}
protected ExitStatus run(Collection<String> args) throws IOException {
this.process = new RunProcess(this.command);
int code = this.process.run(true, StringUtils.toStringArray(args));
RunProcess process = new RunProcess(this.command);
this.process = process;
int code = process.run(true, StringUtils.toStringArray(args));
if (code == 0) {
return ExitStatus.OK;
}
@@ -63,8 +64,9 @@ class RunProcessCommand extends AbstractCommand {
}
boolean handleSigInt() {
Assert.state(this.process != null, "'process' must not be null");
return this.process.handleSigInt();
RunProcess process = this.process;
Assert.state(process != null, "'process' must not be null");
return process.handleSigInt();
}
}