Skip to content

Commit f51f872

Browse files
committed
Improve null-safety of module/spring-boot-actuator
See gh-46926
1 parent 552c145 commit f51f872

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class AuditEvent implements Serializable {
6161
* @param type the event type
6262
* @param data the event data
6363
*/
64-
public AuditEvent(String principal, String type, Map<String, @Nullable Object> data) {
64+
public AuditEvent(@Nullable String principal, String type, Map<String, @Nullable Object> data) {
6565
this(Instant.now(), principal, type, data);
6666
}
6767

@@ -72,7 +72,7 @@ public AuditEvent(String principal, String type, Map<String, @Nullable Object> d
7272
* @param type the event type
7373
* @param data the event data in the form 'key=value' or simply 'key'
7474
*/
75-
public AuditEvent(String principal, String type, String... data) {
75+
public AuditEvent(@Nullable String principal, String type, String... data) {
7676
this(Instant.now(), principal, type, convert(data));
7777
}
7878

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public AuditEventsEndpoint(AuditEventRepository auditEventRepository) {
4545
}
4646

4747
@ReadOperation
48-
public AuditEventsDescriptor events(@OptionalParameter String principal, @OptionalParameter OffsetDateTime after,
49-
@OptionalParameter String type) {
48+
public AuditEventsDescriptor events(@OptionalParameter @Nullable String principal,
49+
@OptionalParameter @Nullable OffsetDateTime after, @OptionalParameter @Nullable String type) {
5050
List<AuditEvent> events = this.auditEventRepository.find(principal, getInstant(after), type);
5151
return new AuditEventsDescriptor(events);
5252
}

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public EnvironmentEndpoint(Environment environment, Iterable<SanitizingFunction>
8181
}
8282

8383
@ReadOperation
84-
public EnvironmentDescriptor environment(@OptionalParameter String pattern) {
84+
public EnvironmentDescriptor environment(@OptionalParameter @Nullable String pattern) {
8585
boolean showUnsanitized = this.showValues.isShown(true);
8686
return getEnvironmentDescriptor(pattern, showUnsanitized);
8787
}
8888

89-
EnvironmentDescriptor getEnvironmentDescriptor(String pattern, boolean showUnsanitized) {
89+
EnvironmentDescriptor getEnvironmentDescriptor(@Nullable String pattern, boolean showUnsanitized) {
9090
if (StringUtils.hasText(pattern)) {
9191
return getEnvironmentDescriptor(Pattern.compile(pattern).asPredicate(), showUnsanitized);
9292
}

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpointWebExtension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Set;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.actuate.endpoint.SecurityContext;
2224
import org.springframework.boot.actuate.endpoint.Show;
2325
import org.springframework.boot.actuate.endpoint.annotation.OptionalParameter;
@@ -51,7 +53,8 @@ public EnvironmentEndpointWebExtension(EnvironmentEndpoint delegate, Show showVa
5153
}
5254

5355
@ReadOperation
54-
public EnvironmentDescriptor environment(SecurityContext securityContext, @OptionalParameter String pattern) {
56+
public EnvironmentDescriptor environment(SecurityContext securityContext,
57+
@OptionalParameter @Nullable String pattern) {
5558
boolean showUnsanitized = this.showValues.isShown(securityContext, this.roles);
5659
return this.delegate.getEnvironmentDescriptor(pattern, showUnsanitized);
5760
}

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/logging/LoggersEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private Map<String, GroupLoggerLevelsDescriptor> getGroups() {
100100
}
101101

102102
@WriteOperation
103-
public void configureLogLevel(@Selector String name, @OptionalParameter LogLevel configuredLevel) {
103+
public void configureLogLevel(@Selector String name, @OptionalParameter @Nullable LogLevel configuredLevel) {
104104
Assert.notNull(name, "'name' must not be empty");
105105
LoggerGroup group = this.loggerGroups.get(name);
106106
if (group != null && group.hasMembers()) {

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected HeapDumpWebEndpoint(long timeout) {
7878
}
7979

8080
@ReadOperation
81-
public WebEndpointResponse<Resource> heapDump(@OptionalParameter Boolean live) {
81+
public WebEndpointResponse<Resource> heapDump(@OptionalParameter @Nullable Boolean live) {
8282
try {
8383
if (this.lock.tryLock(this.timeout, TimeUnit.MILLISECONDS)) {
8484
try {
@@ -101,7 +101,7 @@ public WebEndpointResponse<Resource> heapDump(@OptionalParameter Boolean live) {
101101
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_TOO_MANY_REQUESTS);
102102
}
103103

104-
private Resource dumpHeap(Boolean live) throws IOException, InterruptedException {
104+
private Resource dumpHeap(@Nullable Boolean live) throws IOException, InterruptedException {
105105
if (this.heapDumper == null) {
106106
this.heapDumper = createHeapDumper();
107107
}

0 commit comments

Comments
 (0)