Skip to content

Commit 3207f57

Browse files
committed
Add nullability annotations to module/spring-boot-observation
See gh-46587
1 parent 8e18a3f commit 3207f57

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

module/spring-boot-observation/src/main/java/org/springframework/boot/observation/autoconfigure/ObservationHandlerGroups.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import io.micrometer.observation.ObservationHandler;
2525
import io.micrometer.observation.ObservationRegistry.ObservationConfig;
26+
import org.jspecify.annotations.Nullable;
2627

2728
import org.springframework.util.CollectionUtils;
2829
import org.springframework.util.LinkedMultiValueMap;
@@ -52,24 +53,30 @@ private static List<ObservationHandlerGroup> sort(Collection<? extends Observati
5253

5354
void register(ObservationConfig config, List<ObservationHandler<?>> handlers) {
5455
MultiValueMap<ObservationHandlerGroup, ObservationHandler<?>> grouped = new LinkedMultiValueMap<>();
56+
List<ObservationHandler<?>> unclaimed = new ArrayList<>();
5557
for (ObservationHandler<?> handler : handlers) {
56-
grouped.add(findGroup(handler), handler);
58+
ObservationHandlerGroup group = findGroup(handler);
59+
if (group == null) {
60+
unclaimed.add(handler);
61+
}
62+
else {
63+
grouped.add(group, handler);
64+
}
5765
}
5866
for (ObservationHandlerGroup group : this.groups) {
5967
List<ObservationHandler<?>> members = grouped.get(group);
6068
if (!CollectionUtils.isEmpty(members)) {
6169
group.registerMembers(config, members);
6270
}
6371
}
64-
List<ObservationHandler<?>> unclaimed = grouped.get(null);
6572
if (!CollectionUtils.isEmpty(unclaimed)) {
6673
for (ObservationHandler<?> handler : unclaimed) {
6774
config.observationHandler(handler);
6875
}
6976
}
7077
}
7178

72-
private ObservationHandlerGroup findGroup(ObservationHandler<?> handler) {
79+
private @Nullable ObservationHandlerGroup findGroup(ObservationHandler<?> handler) {
7380
for (ObservationHandlerGroup group : this.groups) {
7481
if (group.isMember(handler)) {
7582
return group;

module/spring-boot-observation/src/main/java/org/springframework/boot/observation/autoconfigure/ObservationRegistryPostProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.micrometer.observation.ObservationHandler;
2222
import io.micrometer.observation.ObservationPredicate;
2323
import io.micrometer.observation.ObservationRegistry;
24+
import org.jspecify.annotations.Nullable;
2425

2526
import org.springframework.beans.BeansException;
2627
import org.springframework.beans.factory.ObjectProvider;
@@ -47,7 +48,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
4748

4849
private final ObjectProvider<ObservationFilter> observationFilters;
4950

50-
private volatile ObservationRegistryConfigurer configurer;
51+
private volatile @Nullable ObservationRegistryConfigurer configurer;
5152

5253
ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
5354
ObjectProvider<ObservationPredicate> observationPredicates,

module/spring-boot-observation/src/main/java/org/springframework/boot/observation/autoconfigure/SpelValueExpressionResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
package org.springframework.boot.observation.autoconfigure;
1818

1919
import io.micrometer.common.annotation.ValueExpressionResolver;
20+
import org.jspecify.annotations.Nullable;
2021

2122
import org.springframework.expression.Expression;
2223
import org.springframework.expression.ExpressionParser;
2324
import org.springframework.expression.spel.standard.SpelExpressionParser;
2425
import org.springframework.expression.spel.support.SimpleEvaluationContext;
26+
import org.springframework.util.Assert;
2527

2628
/**
2729
* A {@link Expression SpEL}-based {@link ValueExpressionResolver}.
@@ -33,11 +35,13 @@ class SpelValueExpressionResolver implements ValueExpressionResolver {
3335
private final ExpressionParser expressionParser = new SpelExpressionParser();
3436

3537
@Override
36-
public String resolve(String expression, Object parameter) {
38+
public String resolve(String expression, @Nullable Object parameter) {
3739
try {
3840
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
3941
Expression expressionToEvaluate = this.expressionParser.parseExpression(expression);
40-
return expressionToEvaluate.getValue(context, parameter, String.class);
42+
String value = expressionToEvaluate.getValue(context, parameter, String.class);
43+
Assert.state(value != null, "'value' must not be null");
44+
return value;
4145
}
4246
catch (Exception ex) {
4347
throw new IllegalStateException("Unable to evaluate SpEL expression '%s'".formatted(expression), ex);

module/spring-boot-observation/src/main/java/org/springframework/boot/observation/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Micrometer Observation.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.observation.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)