Skip to content

Commit fb56734

Browse files
authored
add Nullaway (#1511)
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent df6c250 commit fb56734

File tree

83 files changed

+749
-531
lines changed

Some content is hidden

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

83 files changed

+749
-531
lines changed

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@
267267
-Xep:MissingSummary:OFF
268268
-Xep:LongDoubleConversion:OFF
269269
-Xep:StringSplitter:OFF
270-
-XepExcludedPaths:.*/generated/.*
270+
-XepExcludedPaths:(.*/generated/.*|.*/src/test/java/.*|.*/examples/.*|.*/integration-tests/.*)
271+
-XepOpt:NullAway:AnnotatedPackages=io.prometheus.metrics
271272
</arg>
272273
</compilerArgs>
273274
<annotationProcessorPaths>
@@ -276,6 +277,11 @@
276277
<artifactId>error_prone_core</artifactId>
277278
<version>2.41.0</version>
278279
</path>
280+
<path>
281+
<groupId>com.uber.nullaway</groupId>
282+
<artifactId>nullaway</artifactId>
283+
<version>0.12.8</version>
284+
</path>
279285
<!-- Other annotation processors go here.
280286
281287
If 'annotationProcessorPaths' is set, processors will no longer be

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExemplarsProperties.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.prometheus.metrics.config;
22

33
import java.util.Map;
4+
import javax.annotation.Nullable;
45

56
/** Properties starting with io.prometheus.exemplars */
67
public class ExemplarsProperties {
@@ -10,14 +11,14 @@ public class ExemplarsProperties {
1011
private static final String MAX_RETENTION_PERIOD_SECONDS = "maxRetentionPeriodSeconds";
1112
private static final String SAMPLE_INTERVAL_MILLISECONDS = "sampleIntervalMilliseconds";
1213

13-
private final Integer minRetentionPeriodSeconds;
14-
private final Integer maxRetentionPeriodSeconds;
15-
private final Integer sampleIntervalMilliseconds;
14+
@Nullable private final Integer minRetentionPeriodSeconds;
15+
@Nullable private final Integer maxRetentionPeriodSeconds;
16+
@Nullable private final Integer sampleIntervalMilliseconds;
1617

1718
private ExemplarsProperties(
18-
Integer minRetentionPeriodSeconds,
19-
Integer maxRetentionPeriodSeconds,
20-
Integer sampleIntervalMilliseconds) {
19+
@Nullable Integer minRetentionPeriodSeconds,
20+
@Nullable Integer maxRetentionPeriodSeconds,
21+
@Nullable Integer sampleIntervalMilliseconds) {
2122
this.minRetentionPeriodSeconds = minRetentionPeriodSeconds;
2223
this.maxRetentionPeriodSeconds = maxRetentionPeriodSeconds;
2324
this.sampleIntervalMilliseconds = sampleIntervalMilliseconds;
@@ -28,6 +29,7 @@ private ExemplarsProperties(
2829
*
2930
* <p>Default see {@code ExemplarSamplerConfig.DEFAULT_MIN_RETENTION_PERIOD_SECONDS}
3031
*/
32+
@Nullable
3133
public Integer getMinRetentionPeriodSeconds() {
3234
return minRetentionPeriodSeconds;
3335
}
@@ -37,6 +39,7 @@ public Integer getMinRetentionPeriodSeconds() {
3739
*
3840
* <p>Default see {@code ExemplarSamplerConfig.DEFAULT_MAX_RETENTION_PERIOD_SECONDS}
3941
*/
42+
@Nullable
4043
public Integer getMaxRetentionPeriodSeconds() {
4144
return maxRetentionPeriodSeconds;
4245
}
@@ -48,6 +51,7 @@ public Integer getMaxRetentionPeriodSeconds() {
4851
*
4952
* <p>Default see {@code ExemplarSamplerConfig.DEFAULT_SAMPLE_INTERVAL_MILLISECONDS}
5053
*/
54+
@Nullable
5155
public Integer getSampleIntervalMilliseconds() {
5256
return sampleIntervalMilliseconds;
5357
}
@@ -108,9 +112,9 @@ public static Builder builder() {
108112

109113
public static class Builder {
110114

111-
private Integer minRetentionPeriodSeconds;
112-
private Integer maxRetentionPeriodSeconds;
113-
private Integer sampleIntervalMilliseconds;
115+
@Nullable private Integer minRetentionPeriodSeconds;
116+
@Nullable private Integer maxRetentionPeriodSeconds;
117+
@Nullable private Integer sampleIntervalMilliseconds;
114118

115119
private Builder() {}
116120

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collections;
66
import java.util.List;
77
import java.util.Map;
8+
import javax.annotation.Nullable;
89

910
/** Properties starting with io.prometheus.exporter.filter */
1011
public class ExporterFilterProperties {
@@ -15,16 +16,16 @@ public class ExporterFilterProperties {
1516
public static final String METRIC_NAME_MUST_NOT_START_WITH = "metricNameMustNotStartWith";
1617
private static final String PREFIX = "io.prometheus.exporter.filter";
1718

18-
private final List<String> allowedNames;
19-
private final List<String> excludedNames;
20-
private final List<String> allowedPrefixes;
21-
private final List<String> excludedPrefixes;
19+
@Nullable private final List<String> allowedNames;
20+
@Nullable private final List<String> excludedNames;
21+
@Nullable private final List<String> allowedPrefixes;
22+
@Nullable private final List<String> excludedPrefixes;
2223

2324
private ExporterFilterProperties(
24-
List<String> allowedNames,
25-
List<String> excludedNames,
26-
List<String> allowedPrefixes,
27-
List<String> excludedPrefixes) {
25+
@Nullable List<String> allowedNames,
26+
@Nullable List<String> excludedNames,
27+
@Nullable List<String> allowedPrefixes,
28+
@Nullable List<String> excludedPrefixes) {
2829
this.allowedNames =
2930
allowedNames == null ? null : Collections.unmodifiableList(new ArrayList<>(allowedNames));
3031
this.excludedNames =
@@ -39,18 +40,22 @@ private ExporterFilterProperties(
3940
: Collections.unmodifiableList(new ArrayList<>(excludedPrefixes));
4041
}
4142

43+
@Nullable
4244
public List<String> getAllowedMetricNames() {
4345
return allowedNames;
4446
}
4547

48+
@Nullable
4649
public List<String> getExcludedMetricNames() {
4750
return excludedNames;
4851
}
4952

53+
@Nullable
5054
public List<String> getAllowedMetricNamePrefixes() {
5155
return allowedPrefixes;
5256
}
5357

58+
@Nullable
5459
public List<String> getExcludedMetricNamePrefixes() {
5560
return excludedPrefixes;
5661
}
@@ -79,10 +84,10 @@ public static Builder builder() {
7984

8085
public static class Builder {
8186

82-
private List<String> allowedNames;
83-
private List<String> excludedNames;
84-
private List<String> allowedPrefixes;
85-
private List<String> excludedPrefixes;
87+
@Nullable private List<String> allowedNames;
88+
@Nullable private List<String> excludedNames;
89+
@Nullable private List<String> allowedPrefixes;
90+
@Nullable private List<String> excludedPrefixes;
8691

8792
private Builder() {}
8893

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterHttpServerProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package io.prometheus.metrics.config;
22

33
import java.util.Map;
4+
import javax.annotation.Nullable;
45

56
/** Properties starting with io.prometheus.exporter.httpServer */
67
public class ExporterHttpServerProperties {
78

89
private static final String PORT = "port";
910
private static final String PREFIX = "io.prometheus.exporter.httpServer";
10-
private final Integer port;
11+
@Nullable private final Integer port;
1112

12-
private ExporterHttpServerProperties(Integer port) {
13+
private ExporterHttpServerProperties(@Nullable Integer port) {
1314
this.port = port;
1415
}
1516

17+
@Nullable
1618
public Integer getPort() {
1719
return port;
1820
}
@@ -34,7 +36,7 @@ public static Builder builder() {
3436

3537
public static class Builder {
3638

37-
private Integer port;
39+
@Nullable private Integer port;
3840

3941
private Builder() {}
4042

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterOpenTelemetryProperties.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import javax.annotation.Nullable;
56

67
// TODO: JavaDoc is currently only in OpenTelemetryExporter.Builder. Look there for reference.
78
public class ExporterOpenTelemetryProperties {
@@ -21,27 +22,27 @@ public class ExporterOpenTelemetryProperties {
2122
"resourceAttributes"; // otel.resource.attributes
2223
private static final String PREFIX = "io.prometheus.exporter.opentelemetry";
2324

24-
private final String protocol;
25-
private final String endpoint;
25+
@Nullable private final String endpoint;
26+
@Nullable private final String protocol;
2627
private final Map<String, String> headers;
27-
private final String interval;
28-
private final String timeout;
29-
private final String serviceName;
30-
private final String serviceNamespace;
31-
private final String serviceInstanceId;
32-
private final String serviceVersion;
28+
@Nullable private final String interval;
29+
@Nullable private final String timeout;
30+
@Nullable private final String serviceName;
31+
@Nullable private final String serviceNamespace;
32+
@Nullable private final String serviceInstanceId;
33+
@Nullable private final String serviceVersion;
3334
private final Map<String, String> resourceAttributes;
3435

3536
private ExporterOpenTelemetryProperties(
36-
String protocol,
37-
String endpoint,
37+
@Nullable String protocol,
38+
@Nullable String endpoint,
3839
Map<String, String> headers,
39-
String interval,
40-
String timeout,
41-
String serviceName,
42-
String serviceNamespace,
43-
String serviceInstanceId,
44-
String serviceVersion,
40+
@Nullable String interval,
41+
@Nullable String timeout,
42+
@Nullable String serviceName,
43+
@Nullable String serviceNamespace,
44+
@Nullable String serviceInstanceId,
45+
@Nullable String serviceVersion,
4546
Map<String, String> resourceAttributes) {
4647
this.protocol = protocol;
4748
this.endpoint = endpoint;
@@ -55,10 +56,12 @@ private ExporterOpenTelemetryProperties(
5556
this.resourceAttributes = resourceAttributes;
5657
}
5758

59+
@Nullable
5860
public String getProtocol() {
5961
return protocol;
6062
}
6163

64+
@Nullable
6265
public String getEndpoint() {
6366
return endpoint;
6467
}
@@ -67,26 +70,32 @@ public Map<String, String> getHeaders() {
6770
return headers;
6871
}
6972

73+
@Nullable
7074
public String getInterval() {
7175
return interval;
7276
}
7377

78+
@Nullable
7479
public String getTimeout() {
7580
return timeout;
7681
}
7782

83+
@Nullable
7884
public String getServiceName() {
7985
return serviceName;
8086
}
8187

88+
@Nullable
8289
public String getServiceNamespace() {
8390
return serviceNamespace;
8491
}
8592

93+
@Nullable
8694
public String getServiceInstanceId() {
8795
return serviceInstanceId;
8896
}
8997

98+
@Nullable
9099
public String getServiceVersion() {
91100
return serviceVersion;
92101
}
@@ -131,15 +140,15 @@ public static Builder builder() {
131140

132141
public static class Builder {
133142

134-
private String protocol;
135-
private String endpoint;
143+
@Nullable private String protocol;
144+
@Nullable private String endpoint;
136145
private final Map<String, String> headers = new HashMap<>();
137-
private String interval;
138-
private String timeout;
139-
private String serviceName;
140-
private String serviceNamespace;
141-
private String serviceInstanceId;
142-
private String serviceVersion;
146+
@Nullable private String interval;
147+
@Nullable private String timeout;
148+
@Nullable private String serviceName;
149+
@Nullable private String serviceNamespace;
150+
@Nullable private String serviceInstanceId;
151+
@Nullable private String serviceVersion;
143152
private final Map<String, String> resourceAttributes = new HashMap<>();
144153

145154
private Builder() {}

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterProperties.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.prometheus.metrics.config;
22

33
import java.util.Map;
4+
import javax.annotation.Nullable;
45

56
/** Properties starting with io.prometheus.exporter */
67
public class ExporterProperties {
@@ -11,14 +12,14 @@ public class ExporterProperties {
1112
private static final String EXEMPLARS_ON_ALL_METRIC_TYPES = "exemplarsOnAllMetricTypes";
1213
private static final String PREFIX = "io.prometheus.exporter";
1314

14-
private final Boolean includeCreatedTimestamps;
15-
private final Boolean prometheusTimestampsInMs;
16-
private final Boolean exemplarsOnAllMetricTypes;
15+
@Nullable private final Boolean includeCreatedTimestamps;
16+
@Nullable private final Boolean prometheusTimestampsInMs;
17+
@Nullable private final Boolean exemplarsOnAllMetricTypes;
1718

1819
private ExporterProperties(
19-
Boolean includeCreatedTimestamps,
20-
Boolean prometheusTimestampsInMs,
21-
Boolean exemplarsOnAllMetricTypes) {
20+
@Nullable Boolean includeCreatedTimestamps,
21+
@Nullable Boolean prometheusTimestampsInMs,
22+
@Nullable Boolean exemplarsOnAllMetricTypes) {
2223
this.includeCreatedTimestamps = includeCreatedTimestamps;
2324
this.prometheusTimestampsInMs = prometheusTimestampsInMs;
2425
this.exemplarsOnAllMetricTypes = exemplarsOnAllMetricTypes;
@@ -64,8 +65,8 @@ public static Builder builder() {
6465

6566
public static class Builder {
6667

67-
private Boolean includeCreatedTimestamps;
68-
private Boolean exemplarsOnAllMetricTypes;
68+
@Nullable private Boolean includeCreatedTimestamps;
69+
@Nullable private Boolean exemplarsOnAllMetricTypes;
6970
boolean prometheusTimestampsInMs;
7071

7172
private Builder() {}

0 commit comments

Comments
 (0)