Browse Source

Improve null-safety of module/spring-boot-devtools

See gh-46926
pull/46973/head
Moritz Halbritter 4 months ago
parent
commit
d9750462bc
  1. 7
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/ConditionEvaluationDeltaLoggingListener.java
  2. 4
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Connection.java
  3. 6
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java

7
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/ConditionEvaluationDeltaLoggingListener.java

@ -27,6 +27,7 @@ import org.springframework.boot.context.event.ApplicationReadyEvent; @@ -27,6 +27,7 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.util.Assert;
/**
* An {@link ApplicationListener} that logs the delta of condition evaluation across
@ -50,7 +51,8 @@ class ConditionEvaluationDeltaLoggingListener @@ -50,7 +51,8 @@ class ConditionEvaluationDeltaLoggingListener
return;
}
ConditionEvaluationReport report = event.getApplicationContext().getBean(ConditionEvaluationReport.class);
ConditionEvaluationReport previousReport = previousReports.get(event.getApplicationContext().getId());
String contextId = event.getApplicationContext().getId();
ConditionEvaluationReport previousReport = previousReports.get(contextId);
if (previousReport != null) {
ConditionEvaluationReport delta = report.getDelta(previousReport);
if (!delta.getConditionAndOutcomesBySource().isEmpty() || !delta.getExclusions().isEmpty()
@ -64,7 +66,8 @@ class ConditionEvaluationDeltaLoggingListener @@ -64,7 +66,8 @@ class ConditionEvaluationDeltaLoggingListener
logger.info("Condition evaluation unchanged");
}
}
previousReports.put(event.getApplicationContext().getId(), report);
Assert.state(contextId != null, "'contextId' must not be null");
previousReports.put(contextId, report);
}
@Override

4
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Connection.java

@ -87,7 +87,9 @@ class Connection { @@ -87,7 +87,9 @@ class Connection {
runWebSocket();
}
if (lowerCaseHeader.contains("get /livereload.js")) {
this.outputStream.writeHttp(getClass().getResourceAsStream("livereload.js"), "text/javascript");
InputStream stream = getClass().getResourceAsStream("livereload.js");
Assert.state(stream != null, "Resource 'livereload.js' not found");
this.outputStream.writeHttp(stream, "text/javascript");
}
}

6
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFileURLStreamHandler.java

@ -23,6 +23,8 @@ import java.net.URL; @@ -23,6 +23,8 @@ import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.springframework.util.Assert;
/**
* {@link URLStreamHandler} for the contents of a {@link ClassLoaderFile}.
*
@ -54,7 +56,9 @@ public class ClassLoaderFileURLStreamHandler extends URLStreamHandler { @@ -54,7 +56,9 @@ public class ClassLoaderFileURLStreamHandler extends URLStreamHandler {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(ClassLoaderFileURLStreamHandler.this.file.getContents());
byte[] contents = ClassLoaderFileURLStreamHandler.this.file.getContents();
Assert.state(contents != null, "'contents' must not be null");
return new ByteArrayInputStream(contents);
}
@Override

Loading…
Cancel
Save