Skip to content

Commit 50920f2

Browse files
committed
Add nullability annotations to module/spring-boot-actuator
See gh-46587
1 parent 2d256c2 commit 50920f2

File tree

123 files changed

+642
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+642
-319
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.fasterxml.jackson.annotation.JsonInclude;
2626
import com.fasterxml.jackson.annotation.JsonInclude.Include;
27+
import org.jspecify.annotations.Nullable;
2728

2829
import org.springframework.context.ApplicationEventPublisher;
2930
import org.springframework.context.ApplicationEventPublisherAware;
@@ -82,7 +83,7 @@ public AuditEvent(String principal, String type, String... data) {
8283
* @param type the event type
8384
* @param data the event data
8485
*/
85-
public AuditEvent(Instant timestamp, String principal, String type, Map<String, Object> data) {
86+
public AuditEvent(Instant timestamp, @Nullable String principal, String type, Map<String, Object> data) {
8687
Assert.notNull(timestamp, "'timestamp' must not be null");
8788
Assert.notNull(type, "'type' must not be null");
8889
this.timestamp = timestamp;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Instant;
2020
import java.util.List;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
/**
2325
* Repository for {@link AuditEvent}s.
2426
*
@@ -44,6 +46,6 @@ public interface AuditEventRepository {
4446
* @return audit events of specified type relating to the principal
4547
* @since 1.4.0
4648
*/
47-
List<AuditEvent> find(String principal, Instant after, String type);
49+
List<AuditEvent> find(@Nullable String principal, @Nullable Instant after, @Nullable String type);
4850

4951
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.time.OffsetDateTime;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
2426
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
2527
import org.springframework.boot.actuate.endpoint.annotation.OptionalParameter;
@@ -49,7 +51,7 @@ public AuditEventsDescriptor events(@OptionalParameter String principal, @Option
4951
return new AuditEventsDescriptor(events);
5052
}
5153

52-
private Instant getInstant(OffsetDateTime offsetDateTime) {
54+
private @Nullable Instant getInstant(@Nullable OffsetDateTime offsetDateTime) {
5355
return (offsetDateTime != null) ? offsetDateTime.toInstant() : null;
5456
}
5557

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.LinkedList;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.util.Assert;
2426

2527
/**
@@ -71,7 +73,7 @@ public void add(AuditEvent event) {
7173
}
7274

7375
@Override
74-
public List<AuditEvent> find(String principal, Instant after, String type) {
76+
public List<AuditEvent> find(@Nullable String principal, @Nullable Instant after, @Nullable String type) {
7577
LinkedList<AuditEvent> events = new LinkedList<>();
7678
synchronized (this.monitor) {
7779
for (int i = 0; i < this.events.length; i++) {
@@ -84,7 +86,8 @@ public List<AuditEvent> find(String principal, Instant after, String type) {
8486
return events;
8587
}
8688

87-
private boolean isMatch(String principal, Instant after, String type, AuditEvent event) {
89+
private boolean isMatch(@Nullable String principal, @Nullable Instant after, @Nullable String type,
90+
AuditEvent event) {
8891
boolean match = true;
8992
match = match && (principal == null || event.getPrincipal().equals(principal));
9093
match = match && (after == null || event.getTimestamp().isAfter(after));

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator auditing listeners.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.actuate.audit.listener;
22+
23+
import org.jspecify.annotations.NullMarked;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Core actuator auditing classes.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.actuate.audit;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.Map;
2222
import java.util.function.Consumer;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.availability.ApplicationAvailability;
2527
import org.springframework.boot.availability.AvailabilityState;
2628
import org.springframework.boot.health.contributor.AbstractHealthIndicator;
@@ -92,7 +94,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
9294
* @param applicationAvailability the application availability
9395
* @return the current availability state
9496
*/
95-
protected AvailabilityState getState(ApplicationAvailability applicationAvailability) {
97+
protected @Nullable AvailabilityState getState(ApplicationAvailability applicationAvailability) {
9698
return applicationAvailability.getState(this.stateType);
9799
}
98100

@@ -116,7 +118,7 @@ default void addDefaultStatus(Status status) {
116118
* @param availabilityState the availability state
117119
* @param status the mapped status
118120
*/
119-
void add(S availabilityState, Status status);
121+
void add(@Nullable S availabilityState, Status status);
120122

121123
}
122124

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator support for application availability concerns.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.actuate.availability;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/beans/BeansEndpoint.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.beans.factory.config.BeanDefinition;
2325
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2426
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -63,7 +65,8 @@ public BeansDescriptor beans() {
6365
return new BeansDescriptor(contexts);
6466
}
6567

66-
private static ConfigurableApplicationContext getConfigurableParent(ConfigurableApplicationContext context) {
68+
private static @Nullable ConfigurableApplicationContext getConfigurableParent(
69+
ConfigurableApplicationContext context) {
6770
ApplicationContext parent = context.getParent();
6871
if (parent instanceof ConfigurableApplicationContext configurableParent) {
6972
return configurableParent;
@@ -95,22 +98,22 @@ public static final class ContextBeansDescriptor {
9598

9699
private final Map<String, BeanDescriptor> beans;
97100

98-
private final String parentId;
101+
private final @Nullable String parentId;
99102

100-
private ContextBeansDescriptor(Map<String, BeanDescriptor> beans, String parentId) {
103+
private ContextBeansDescriptor(Map<String, BeanDescriptor> beans, @Nullable String parentId) {
101104
this.beans = beans;
102105
this.parentId = parentId;
103106
}
104107

105-
public String getParentId() {
108+
public @Nullable String getParentId() {
106109
return this.parentId;
107110
}
108111

109112
public Map<String, BeanDescriptor> getBeans() {
110113
return this.beans;
111114
}
112115

113-
private static ContextBeansDescriptor describing(ConfigurableApplicationContext context) {
116+
private static @Nullable ContextBeansDescriptor describing(@Nullable ConfigurableApplicationContext context) {
114117
if (context == null) {
115118
return null;
116119
}
@@ -150,15 +153,16 @@ public static final class BeanDescriptor {
150153

151154
private final String[] aliases;
152155

153-
private final String scope;
156+
private final @Nullable String scope;
154157

155-
private final Class<?> type;
158+
private final @Nullable Class<?> type;
156159

157-
private final String resource;
160+
private final @Nullable String resource;
158161

159162
private final String[] dependencies;
160163

161-
private BeanDescriptor(String[] aliases, String scope, Class<?> type, String resource, String[] dependencies) {
164+
private BeanDescriptor(String[] aliases, @Nullable String scope, @Nullable Class<?> type,
165+
@Nullable String resource, String[] dependencies) {
162166
this.aliases = aliases;
163167
this.scope = (StringUtils.hasText(scope) ? scope : ConfigurableBeanFactory.SCOPE_SINGLETON);
164168
this.type = type;
@@ -170,15 +174,15 @@ public String[] getAliases() {
170174
return this.aliases;
171175
}
172176

173-
public String getScope() {
177+
public @Nullable String getScope() {
174178
return this.scope;
175179
}
176180

177-
public Class<?> getType() {
181+
public @Nullable Class<?> getType() {
178182
return this.type;
179183
}
180184

181-
public String getResource() {
185+
public @Nullable String getResource() {
182186
return this.resource;
183187
}
184188

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/beans/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator support relating to Spring Beans.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.actuate.beans;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)