Skip to content

Commit 29c2ba2

Browse files
committed
nullaway
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 3662341 commit 29c2ba2

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/DistributionDataPointSnapshot.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.prometheus.metrics.model.snapshots;
22

3+
import javax.annotation.Nullable;
4+
35
/**
46
* Common base class for histogram and summary data. Histograms and Summaries represent
57
* distributions, like a latency distribution or a distribution of request sizes in Bytes.
@@ -73,7 +75,7 @@ public T sum(double sum) {
7375
return self();
7476
}
7577

76-
public T exemplars(Exemplars exemplars) {
78+
public T exemplars(@Nullable Exemplars exemplars) {
7779
this.exemplars = exemplars;
7880
return self();
7981
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.List;
6+
import javax.annotation.Nullable;
67

78
/** Immutable snapshot of a Histogram. */
89
public final class HistogramSnapshot extends MetricSnapshot {
@@ -398,7 +399,7 @@ protected Builder self() {
398399
return this;
399400
}
400401

401-
public Builder classicHistogramBuckets(ClassicHistogramBuckets classicBuckets) {
402+
public Builder classicHistogramBuckets(@Nullable ClassicHistogramBuckets classicBuckets) {
402403
this.classicHistogramBuckets = classicBuckets;
403404
return this;
404405
}
@@ -419,13 +420,13 @@ public Builder nativeZeroThreshold(double zeroThreshold) {
419420
}
420421

421422
public Builder nativeBucketsForPositiveValues(
422-
NativeHistogramBuckets bucketsForPositiveValues) {
423+
@Nullable NativeHistogramBuckets bucketsForPositiveValues) {
423424
this.nativeBucketsForPositiveValues = bucketsForPositiveValues;
424425
return this;
425426
}
426427

427428
public Builder nativeBucketsForNegativeValues(
428-
NativeHistogramBuckets bucketsForNegativeValues) {
429+
@Nullable NativeHistogramBuckets bucketsForNegativeValues) {
429430
this.nativeBucketsForNegativeValues = bucketsForNegativeValues;
430431
return this;
431432
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public T name(String name) {
6363
return self();
6464
}
6565

66-
public T help(String help) {
66+
public T help(@Nullable String help) {
6767
this.help = help;
6868
return self();
6969
}
7070

71-
public T unit(Unit unit) {
71+
public T unit(@Nullable Unit unit) {
7272
this.unit = unit;
7373
return self();
7474
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.List;
6+
import javax.annotation.Nullable;
67

78
/** Immutable snapshot of a Summary metric. */
89
public final class SummarySnapshot extends MetricSnapshot {
@@ -102,7 +103,7 @@ protected Builder self() {
102103
return this;
103104
}
104105

105-
public Builder quantiles(Quantiles quantiles) {
106+
public Builder quantiles(@Nullable Quantiles quantiles) {
106107
this.quantiles = quantiles;
107108
return this;
108109
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/UnknownSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Builder value(double value) {
8282
}
8383

8484
/** Optional */
85-
public Builder exemplar(Exemplar exemplar) {
85+
public Builder exemplar(@Nullable Exemplar exemplar) {
8686
this.exemplar = exemplar;
8787
return this;
8888
}

prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java

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

33
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.sanitizeMetricName;
4+
import static java.util.Objects.requireNonNull;
45

56
import io.prometheus.client.Collector;
67
import io.prometheus.client.CollectorRegistry;
@@ -29,6 +30,7 @@
2930
import java.util.HashMap;
3031
import java.util.List;
3132
import java.util.Map;
33+
import javax.annotation.Nullable;
3234

3335
/**
3436
* Bridge from {@code simpleclient} (version 0.16.0 and older) to the new {@code prometheus-metrics}
@@ -183,10 +185,9 @@ private MetricSnapshot convertHistogram(
183185
}
184186
for (Labels labels : dataPoints.keySet()) {
185187
histogram.dataPoint(
186-
dataPoints
187-
.get(labels)
188-
.classicHistogramBuckets(makeBuckets(cumulativeBuckets.get(labels)))
189-
.exemplars(exemplars.get(labels).build())
188+
requireNonNull(dataPoints.get(labels))
189+
.classicHistogramBuckets(makeBuckets(requireNonNull(cumulativeBuckets.get(labels))))
190+
.exemplars(requireNonNull(exemplars.get(labels)).build())
190191
.build());
191192
}
192193
return histogram.build();
@@ -233,10 +234,9 @@ private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) {
233234
}
234235
for (Labels labels : dataPoints.keySet()) {
235236
summary.dataPoint(
236-
dataPoints
237-
.get(labels)
238-
.quantiles(quantiles.get(labels).build())
239-
.exemplars(exemplars.get(labels).build())
237+
requireNonNull(dataPoints.get(labels))
238+
.quantiles(requireNonNull(quantiles.get(labels)).build())
239+
.exemplars(requireNonNull(exemplars.get(labels)).build())
240240
.build());
241241
}
242242
return summary.build();
@@ -291,6 +291,7 @@ private MetricSnapshot convertUnknown(Collector.MetricFamilySamples samples) {
291291
return unknown.build();
292292
}
293293

294+
@Nullable
294295
private Unit convertUnit(Collector.MetricFamilySamples samples) {
295296
if (samples.unit != null && !samples.unit.isEmpty()) {
296297
return new Unit(samples.unit);
@@ -306,7 +307,7 @@ private ClassicHistogramBuckets makeBuckets(Map<Double, Long> cumulativeBuckets)
306307
ClassicHistogramBuckets.Builder result = ClassicHistogramBuckets.builder();
307308
long previousCount = 0L;
308309
for (Double upperBound : upperBounds) {
309-
long cumulativeCount = cumulativeBuckets.get(upperBound);
310+
long cumulativeCount = requireNonNull(cumulativeBuckets.get(upperBound));
310311
result.bucket(upperBound, cumulativeCount - previousCount);
311312
previousCount = cumulativeCount;
312313
}
@@ -357,7 +358,8 @@ private MetricSnapshot convertInfo(Collector.MetricFamilySamples samples) {
357358
return info.build();
358359
}
359360

360-
private Exemplar convertExemplar(io.prometheus.client.exemplars.Exemplar exemplar) {
361+
@Nullable
362+
private Exemplar convertExemplar(@Nullable io.prometheus.client.exemplars.Exemplar exemplar) {
361363
if (exemplar == null) {
362364
return null;
363365
}
@@ -388,7 +390,7 @@ public static Builder builder() {
388390

389391
public static class Builder {
390392

391-
private CollectorRegistry collectorRegistry;
393+
@Nullable private CollectorRegistry collectorRegistry;
392394

393395
private Builder() {}
394396

0 commit comments

Comments
 (0)