Skip to content

Commit 19ec929

Browse files
committed
Add nullability annotations to module/spring-boot-opentelemetry
See gh-46587
1 parent 3207f57 commit 19ec929

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/OpenTelemetryResourceAttributes.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.function.BiConsumer;
2525
import java.util.function.Function;
2626

27+
import org.jspecify.annotations.Nullable;
28+
2729
import org.springframework.core.env.Environment;
2830
import org.springframework.util.Assert;
2931
import org.springframework.util.StringUtils;
@@ -52,7 +54,7 @@ public class OpenTelemetryResourceAttributes {
5254

5355
private final Map<String, String> resourceAttributes;
5456

55-
private final Function<String, String> systemEnvironment;
57+
private final Function<String, @Nullable String> systemEnvironment;
5658

5759
/**
5860
* Creates a new instance of {@link OpenTelemetryResourceAttributes}.
@@ -69,8 +71,8 @@ public OpenTelemetryResourceAttributes(Environment environment, Map<String, Stri
6971
* @param resourceAttributes user-provided resource attributes to be used
7072
* @param systemEnvironment a function to retrieve environment variables by name
7173
*/
72-
OpenTelemetryResourceAttributes(Environment environment, Map<String, String> resourceAttributes,
73-
Function<String, String> systemEnvironment) {
74+
OpenTelemetryResourceAttributes(Environment environment, @Nullable Map<String, String> resourceAttributes,
75+
@Nullable Function<String, @Nullable String> systemEnvironment) {
7476
Assert.notNull(environment, "'environment' must not be null");
7577
this.environment = environment;
7678
this.resourceAttributes = (resourceAttributes != null) ? resourceAttributes : Collections.emptyMap();
@@ -106,7 +108,7 @@ private String getApplicationName() {
106108
return this.environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME);
107109
}
108110

109-
private String getServiceNamespace() {
111+
private @Nullable String getServiceNamespace() {
110112
return this.environment.getProperty("spring.application.group");
111113
}
112114

@@ -137,7 +139,7 @@ private Map<String, String> getResourceAttributesFromEnv() {
137139
return attributes;
138140
}
139141

140-
private String getEnv(String name) {
142+
private @Nullable String getEnv(String name) {
141143
return this.systemEnvironment.apply(name);
142144
}
143145

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/OpenTelemetryLoggingConnectionDetailsConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public String getUrl(Transport transport) {
5555
Assert.state(transport == this.properties.getTransport(),
5656
"Requested transport %s doesn't match configured transport %s".formatted(transport,
5757
this.properties.getTransport()));
58-
return this.properties.getEndpoint();
58+
String endpoint = this.properties.getEndpoint();
59+
Assert.state(endpoint != null, "'endpoint' must not be null");
60+
return endpoint;
5961
}
6062

6163
}

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/OpenTelemetryLoggingExportProperties.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 OpenTelemetryLoggingExportProperties {
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 OpenTelemetryLoggingExportProperties {
6466
*/
6567
private final 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-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/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 logs with OpenTelemetry.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.opentelemetry.autoconfigure.logging;
22+
23+
import org.jspecify.annotations.NullMarked;

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

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/docker/compose/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Support for Docker Compose OpenTelemetry logging service connections.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.opentelemetry.docker.compose;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/testcontainers/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Support for Testcontainers OpenTelemetry logging service connections.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.opentelemetry.testcontainers;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)