Skip to content

Commit 89a5bfd

Browse files
committed
Add nullability annotations to module/spring-boot-tracing
See gh-46587
1 parent 598ee98 commit 89a5bfd

16 files changed

+60
-25
lines changed

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/BravePropagationConfigurations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import brave.propagation.Propagation;
3232
import brave.propagation.Propagation.Factory;
3333
import io.micrometer.tracing.brave.bridge.BraveBaggageManager;
34+
import org.jspecify.annotations.Nullable;
3435

3536
import org.springframework.beans.factory.ObjectProvider;
3637
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
@@ -103,7 +104,7 @@ private Factory createThrowAwayFactory() {
103104
return new Factory() {
104105

105106
@Override
106-
public Propagation<String> get() {
107+
public @Nullable Propagation<String> get() {
107108
return null;
108109
}
109110

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/CompositePropagationFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import brave.propagation.TraceContextOrSamplingFlags;
3030
import io.micrometer.tracing.BaggageManager;
3131
import io.micrometer.tracing.brave.bridge.W3CPropagation;
32+
import org.jspecify.annotations.Nullable;
3233

3334
import org.springframework.boot.tracing.autoconfigure.TracingProperties.Propagation.PropagationType;
3435

@@ -107,8 +108,8 @@ static CompositePropagationFactory create(TracingProperties.Propagation properti
107108
* @param localFields the local fields, or {@code null}
108109
* @return the {@link CompositePropagationFactory}
109110
*/
110-
static CompositePropagationFactory create(TracingProperties.Propagation properties, BaggageManager baggageManager,
111-
LocalBaggageFields localFields) {
111+
static CompositePropagationFactory create(TracingProperties.Propagation properties,
112+
@Nullable BaggageManager baggageManager, @Nullable LocalBaggageFields localFields) {
112113
PropagationFactoryMapper mapper = new PropagationFactoryMapper(baggageManager, localFields);
113114
List<Factory> injectors = properties.getEffectiveProducedTypes().stream().map(mapper::map).toList();
114115
List<Factory> extractors = properties.getEffectiveConsumedTypes().stream().map(mapper::map).toList();
@@ -121,11 +122,11 @@ static CompositePropagationFactory create(TracingProperties.Propagation properti
121122
*/
122123
private static class PropagationFactoryMapper {
123124

124-
private final BaggageManager baggageManager;
125+
private final @Nullable BaggageManager baggageManager;
125126

126127
private final LocalBaggageFields localFields;
127128

128-
PropagationFactoryMapper(BaggageManager baggageManager, LocalBaggageFields localFields) {
129+
PropagationFactoryMapper(@Nullable BaggageManager baggageManager, @Nullable LocalBaggageFields localFields) {
129130
this.baggageManager = baggageManager;
130131
this.localFields = (localFields != null) ? localFields : LocalBaggageFields.empty();
131132
}

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/CompositeTextMapPropagator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.opentelemetry.context.propagation.TextMapPropagator;
3333
import io.opentelemetry.context.propagation.TextMapSetter;
3434
import io.opentelemetry.extension.trace.propagation.B3Propagator;
35+
import org.jspecify.annotations.Nullable;
3536

3637
import org.springframework.boot.tracing.autoconfigure.TracingProperties.Propagation.PropagationType;
3738

@@ -48,7 +49,7 @@ class CompositeTextMapPropagator implements TextMapPropagator {
4849

4950
private final Collection<TextMapPropagator> extractors;
5051

51-
private final TextMapPropagator baggagePropagator;
52+
private final @Nullable TextMapPropagator baggagePropagator;
5253

5354
private final Set<String> fields;
5455

@@ -61,7 +62,7 @@ class CompositeTextMapPropagator implements TextMapPropagator {
6162
* @param baggagePropagator the baggage propagator to use, or {@code null}
6263
*/
6364
CompositeTextMapPropagator(Collection<TextMapPropagator> injectors,
64-
Collection<TextMapPropagator> mutuallyExclusiveExtractors, TextMapPropagator baggagePropagator) {
65+
Collection<TextMapPropagator> mutuallyExclusiveExtractors, @Nullable TextMapPropagator baggagePropagator) {
6566
this.injectors = injectors;
6667
this.extractors = mutuallyExclusiveExtractors;
6768
this.baggagePropagator = baggagePropagator;
@@ -92,14 +93,14 @@ public Collection<String> fields() {
9293
}
9394

9495
@Override
95-
public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) {
96+
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
9697
if (context != null && setter != null) {
9798
this.injectors.forEach((injector) -> injector.inject(context, carrier, setter));
9899
}
99100
}
100101

101102
@Override
102-
public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter) {
103+
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
103104
if (context == null) {
104105
return Context.root();
105106
}
@@ -123,7 +124,8 @@ public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter)
123124
* @param baggagePropagator the baggage propagator to use, or {@code null}
124125
* @return the {@link CompositeTextMapPropagator}
125126
*/
126-
static TextMapPropagator create(TracingProperties.Propagation properties, TextMapPropagator baggagePropagator) {
127+
static TextMapPropagator create(TracingProperties.Propagation properties,
128+
@Nullable TextMapPropagator baggagePropagator) {
127129
TextMapPropagatorMapper mapper = new TextMapPropagatorMapper(baggagePropagator != null);
128130
List<TextMapPropagator> injectors = properties.getEffectiveProducedTypes()
129131
.stream()

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/LogCorrelationEnvironmentPostProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.tracing.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.SpringApplication;
2022
import org.springframework.boot.env.EnvironmentPostProcessor;
2123
import org.springframework.boot.logging.LoggingSystem;
@@ -63,7 +65,7 @@ public String[] getPropertyNames() {
6365
}
6466

6567
@Override
66-
public Object getProperty(String name) {
68+
public @Nullable Object getProperty(String name) {
6769
if (name.equals(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY)) {
6870
return this.environment.getProperty("management.tracing.enabled", Boolean.class, Boolean.TRUE);
6971
}

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/OnEnabledTracingCondition.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
2224
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
2325
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
@@ -59,8 +61,9 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
5961
.because("tracing is enabled by default"));
6062
}
6163

62-
private static String getExporterName(AnnotatedTypeMetadata metadata) {
63-
Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
64+
private static @Nullable String getExporterName(AnnotatedTypeMetadata metadata) {
65+
Map<String, @Nullable Object> attributes = metadata
66+
.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
6467
if (attributes == null) {
6568
return null;
6669
}

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/OpenTelemetryEventPublisherBeansApplicationListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.opentelemetry.context.Context;
2525
import io.opentelemetry.context.ContextStorage;
2626
import io.opentelemetry.context.Scope;
27+
import org.jspecify.annotations.Nullable;
2728

2829
import org.springframework.boot.context.event.ApplicationStartingEvent;
2930
import org.springframework.context.ApplicationContext;
@@ -122,7 +123,7 @@ static final class Wrapper {
122123

123124
private final MultiValueMap<ApplicationContext, EventPublishingContextWrapper> beans = new LinkedMultiValueMap<>();
124125

125-
private volatile ContextStorage storageDelegate;
126+
private volatile @Nullable ContextStorage storageDelegate;
126127

127128
private Wrapper() {
128129
}
@@ -181,7 +182,7 @@ public Scope attach(Context toAttach) {
181182
}
182183

183184
@Override
184-
public Context current() {
185+
public @Nullable Context current() {
185186
return getDelegate().current();
186187
}
187188

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/TracingProperties.java

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

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.context.properties.ConfigurationProperties;
2426

2527
/**
@@ -204,7 +206,7 @@ public static class Propagation {
204206
* Setting this property overrides the more fine-grained propagation type
205207
* properties.
206208
*/
207-
private List<PropagationType> type;
209+
private @Nullable List<PropagationType> type;
208210

209211
/**
210212
* Tracing context propagation types produced by the application.
@@ -216,7 +218,7 @@ public static class Propagation {
216218
*/
217219
private List<PropagationType> consume = List.of(PropagationType.values());
218220

219-
public void setType(List<PropagationType> type) {
221+
public void setType(@Nullable List<PropagationType> type) {
220222
this.type = type;
221223
}
222224

@@ -228,7 +230,7 @@ public void setConsume(List<PropagationType> consume) {
228230
this.consume = consume;
229231
}
230232

231-
public List<PropagationType> getType() {
233+
public @Nullable List<PropagationType> getType() {
232234
return this.type;
233235
}
234236

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/otlp/OtlpTracingConfigurations.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public String getUrl(Transport transport) {
6767
Assert.state(transport == this.properties.getTransport(),
6868
"Requested transport %s doesn't match configured transport %s".formatted(transport,
6969
this.properties.getTransport()));
70-
return this.properties.getEndpoint();
70+
String endpoint = this.properties.getEndpoint();
71+
Assert.state(endpoint != null, "'endpoint' must not be null");
72+
return endpoint;
7173
}
7274

7375
}

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/otlp/OtlpTracingProperties.java

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

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.context.properties.ConfigurationProperties;
2426

2527
/**
@@ -34,7 +36,7 @@ public class OtlpTracingProperties {
3436
/**
3537
* URL to the OTel collector's HTTP API.
3638
*/
37-
private String endpoint;
39+
private @Nullable String endpoint;
3840

3941
/**
4042
* Call timeout for the OTel Collector to process an exported batch of data. This
@@ -64,11 +66,11 @@ public class OtlpTracingProperties {
6466
*/
6567
private Map<String, String> headers = new HashMap<>();
6668

67-
public String getEndpoint() {
69+
public @Nullable String getEndpoint() {
6870
return this.endpoint;
6971
}
7072

71-
public void setEndpoint(String endpoint) {
73+
public void setEndpoint(@Nullable String endpoint) {
7274
this.endpoint = endpoint;
7375
}
7476

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/otlp/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 exporting traces with OTLP.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.tracing.autoconfigure.otlp;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)