mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-26 20:09:02 +00:00
Add nullability annotations to module/spring-boot-observation
See gh-46587
This commit is contained in:
+10
-3
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import io.micrometer.observation.ObservationHandler;
|
||||
import io.micrometer.observation.ObservationRegistry.ObservationConfig;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -52,8 +53,15 @@ class ObservationHandlerGroups {
|
||||
|
||||
void register(ObservationConfig config, List<ObservationHandler<?>> handlers) {
|
||||
MultiValueMap<ObservationHandlerGroup, ObservationHandler<?>> grouped = new LinkedMultiValueMap<>();
|
||||
List<ObservationHandler<?>> unclaimed = new ArrayList<>();
|
||||
for (ObservationHandler<?> handler : handlers) {
|
||||
grouped.add(findGroup(handler), handler);
|
||||
ObservationHandlerGroup group = findGroup(handler);
|
||||
if (group == null) {
|
||||
unclaimed.add(handler);
|
||||
}
|
||||
else {
|
||||
grouped.add(group, handler);
|
||||
}
|
||||
}
|
||||
for (ObservationHandlerGroup group : this.groups) {
|
||||
List<ObservationHandler<?>> members = grouped.get(group);
|
||||
@@ -61,7 +69,6 @@ class ObservationHandlerGroups {
|
||||
group.registerMembers(config, members);
|
||||
}
|
||||
}
|
||||
List<ObservationHandler<?>> unclaimed = grouped.get(null);
|
||||
if (!CollectionUtils.isEmpty(unclaimed)) {
|
||||
for (ObservationHandler<?> handler : unclaimed) {
|
||||
config.observationHandler(handler);
|
||||
@@ -69,7 +76,7 @@ class ObservationHandlerGroups {
|
||||
}
|
||||
}
|
||||
|
||||
private ObservationHandlerGroup findGroup(ObservationHandler<?> handler) {
|
||||
private @Nullable ObservationHandlerGroup findGroup(ObservationHandler<?> handler) {
|
||||
for (ObservationHandlerGroup group : this.groups) {
|
||||
if (group.isMember(handler)) {
|
||||
return group;
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import io.micrometer.observation.ObservationFilter;
|
||||
import io.micrometer.observation.ObservationHandler;
|
||||
import io.micrometer.observation.ObservationPredicate;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
@@ -47,7 +48,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private final ObjectProvider<ObservationFilter> observationFilters;
|
||||
|
||||
private volatile ObservationRegistryConfigurer configurer;
|
||||
private volatile @Nullable ObservationRegistryConfigurer configurer;
|
||||
|
||||
ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
|
||||
ObjectProvider<ObservationPredicate> observationPredicates,
|
||||
|
||||
+6
-2
@@ -17,11 +17,13 @@
|
||||
package org.springframework.boot.observation.autoconfigure;
|
||||
|
||||
import io.micrometer.common.annotation.ValueExpressionResolver;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A {@link Expression SpEL}-based {@link ValueExpressionResolver}.
|
||||
@@ -33,11 +35,13 @@ class SpelValueExpressionResolver implements ValueExpressionResolver {
|
||||
private final ExpressionParser expressionParser = new SpelExpressionParser();
|
||||
|
||||
@Override
|
||||
public String resolve(String expression, Object parameter) {
|
||||
public String resolve(String expression, @Nullable Object parameter) {
|
||||
try {
|
||||
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
|
||||
Expression expressionToEvaluate = this.expressionParser.parseExpression(expression);
|
||||
return expressionToEvaluate.getValue(context, parameter, String.class);
|
||||
String value = expressionToEvaluate.getValue(context, parameter, String.class);
|
||||
Assert.state(value != null, "'value' must not be null");
|
||||
return value;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Unable to evaluate SpEL expression '%s'".formatted(expression), ex);
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Auto-configuration for Micrometer Observation.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.observation.autoconfigure;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
Reference in New Issue
Block a user