Browse Source

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

See gh-46926
pull/46973/head
Moritz Halbritter 4 months ago
parent
commit
a0a785ec92
  1. 5
      cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java
  2. 4
      cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java
  3. 10
      cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java

5
cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java

@ -31,6 +31,7 @@ import org.springframework.boot.cli.command.core.HintCommand; @@ -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 { @@ -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());

4
cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java

@ -98,7 +98,9 @@ class ProjectGenerator { @@ -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");

10
cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java

@ -52,8 +52,9 @@ class RunProcessCommand extends AbstractCommand { @@ -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 { @@ -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();
}
}

Loading…
Cancel
Save