Skip to content

Commit 8226348

Browse files
authored
add Errorprone (#1139)
* add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> * add errorprone Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent eb48f5d commit 8226348

File tree

44 files changed

+137
-142
lines changed

Some content is hidden

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

44 files changed

+137
-142
lines changed

.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

examples/example-exporter-multi-target/src/main/java/io/prometheus/metrics/examples/multitarget/SampleMultiCollector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.prometheus.metrics.model.registry.MultiCollector;
44
import io.prometheus.metrics.model.registry.PrometheusScrapeRequest;
55
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
6-
import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot.Builder;
76
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
87
import io.prometheus.metrics.model.snapshots.Labels;
98
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
@@ -46,7 +45,8 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR
4645
} else {
4746
targetName = targetNames[0];
4847
}
49-
Builder counterDataPointBuilder = CounterSnapshot.CounterDataPointSnapshot.builder();
48+
CounterSnapshot.CounterDataPointSnapshot.Builder counterDataPointBuilder =
49+
CounterSnapshot.CounterDataPointSnapshot.builder();
5050
io.prometheus.metrics.model.snapshots.GaugeSnapshot.GaugeDataPointSnapshot.Builder
5151
gaugeDataPointBuilder = GaugeSnapshot.GaugeDataPointSnapshot.builder();
5252
Labels lbls = Labels.of("target", targetName);
@@ -77,6 +77,7 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR
7777
return new MetricSnapshots(snaps);
7878
}
7979

80+
@Override
8081
public List<String> getPrometheusNames() {
8182
List<String> names = new ArrayList<String>();
8283
names.add("x_calls_total");

integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.HashMap;
2020
import java.util.List;
21+
import java.util.Locale;
2122
import java.util.Map;
2223
import java.util.concurrent.TimeUnit;
2324
import java.util.zip.GZIPInputStream;
@@ -67,7 +68,7 @@ public void testOpenMetricsTextFormat() throws IOException {
6768
assertThat(response.getHeader("Transfer-Encoding")).isNull();
6869
assertThat(response.getHeader("Content-Length"))
6970
.isEqualTo(Integer.toString(response.body.length));
70-
String bodyString = new String(response.body);
71+
String bodyString = new String(response.body, UTF_8);
7172
assertThat(bodyString)
7273
.contains("integration_test_info{test_name=\"" + sampleApp + "\"} 1")
7374
.contains("temperature_celsius{location=\"inside\"} 23.0")
@@ -90,7 +91,7 @@ public void testPrometheusTextFormat() throws IOException {
9091
assertThat(response.getHeader("Transfer-Encoding")).isNull();
9192
assertThat(response.getHeader("Content-Length"))
9293
.isEqualTo(Integer.toString(response.body.length));
93-
String bodyString = new String(response.body);
94+
String bodyString = new String(response.body, UTF_8);
9495
assertThat(bodyString)
9596
.contains("integration_test_info{test_name=\"" + sampleApp + "\"} 1")
9697
.contains("temperature_celsius{location=\"inside\"} 23.0")
@@ -370,6 +371,7 @@ private Response scrape(String method, String queryString, String... requestHead
370371
try {
371372
Thread.sleep(100);
372373
} catch (InterruptedException ignored) {
374+
// ignore
373375
}
374376
}
375377
}
@@ -392,14 +394,14 @@ private Response(int status, Map<String, List<String>> headers, byte[] body) {
392394
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
393395
if (entry.getKey()
394396
!= null) { // HttpUrlConnection uses pseudo key "null" for the status line
395-
this.headers.put(entry.getKey().toLowerCase(), entry.getValue().get(0));
397+
this.headers.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue().get(0));
396398
}
397399
}
398400
}
399401

400402
private String getHeader(String name) {
401403
// HTTP headers are case-insensitive
402-
return headers.get(name.toLowerCase());
404+
return headers.get(name.toLowerCase(Locale.ROOT));
403405
}
404406
}
405407
}

integration-tests/it-pushgateway/src/main/java/io/prometheus/metrics/it/pushgateway/PushGatewayTestApp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private static void runSslTest() throws IOException {
7979

8080
static TrustManager insecureTrustManager =
8181
new X509TrustManager() {
82+
@Override
8283
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
8384
return null;
8485
}

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,28 @@
277277
<compilerArgs>
278278
<arg>-Xlint:all</arg>
279279
<arg>-Werror</arg>
280+
<arg>-XDcompilePolicy=simple</arg>
281+
<arg>
282+
-Xplugin:ErrorProne
283+
-Xep:AlmostJavadoc:OFF
284+
-Xep:MissingSummary:OFF
285+
-Xep:LongDoubleConversion:OFF
286+
-Xep:StringSplitter:OFF
287+
-XepExcludedPaths:.*/generated/.*
288+
</arg>
280289
</compilerArgs>
290+
<annotationProcessorPaths>
291+
<path>
292+
<groupId>com.google.errorprone</groupId>
293+
<artifactId>error_prone_core</artifactId>
294+
<version>2.33.0</version>
295+
</path>
296+
<!-- Other annotation processors go here.
297+
298+
If 'annotationProcessorPaths' is set, processors will no longer be
299+
discovered on the regular -classpath; see also 'Using Error Prone
300+
together with other annotation processors' below. -->
301+
</annotationProcessorPaths>
281302
</configuration>
282303
</plugin>
283304
<plugin>

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ private ExporterFilterProperties(
2424
List<String> excludedNames,
2525
List<String> allowedPrefixes,
2626
List<String> excludedPrefixes) {
27-
this(allowedNames, excludedNames, allowedPrefixes, excludedPrefixes, "");
28-
}
29-
30-
private ExporterFilterProperties(
31-
List<String> allowedNames,
32-
List<String> excludedNames,
33-
List<String> allowedPrefixes,
34-
List<String> excludedPrefixes,
35-
String prefix) {
3627
this.allowedNames =
3728
allowedNames == null ? null : Collections.unmodifiableList(new ArrayList<>(allowedNames));
3829
this.excludedNames =
@@ -45,7 +36,6 @@ private ExporterFilterProperties(
4536
excludedPrefixes == null
4637
? null
4738
: Collections.unmodifiableList(new ArrayList<>(excludedPrefixes));
48-
validate(prefix);
4939
}
5040

5141
public List<String> getAllowedMetricNames() {
@@ -64,8 +54,6 @@ public List<String> getExcludedMetricNamePrefixes() {
6454
return excludedPrefixes;
6555
}
6656

67-
private void validate(String prefix) throws PrometheusPropertiesException {}
68-
6957
/**
7058
* Note that this will remove entries from {@code properties}. This is because we want to know if
7159
* there are unused properties remaining after all properties have been loaded.
@@ -81,7 +69,7 @@ static ExporterFilterProperties load(String prefix, Map<Object, Object> properti
8169
List<String> excludedPrefixes =
8270
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_NOT_START_WITH, properties);
8371
return new ExporterFilterProperties(
84-
allowedNames, excludedNames, allowedPrefixes, excludedPrefixes, prefix);
72+
allowedNames, excludedNames, allowedPrefixes, excludedPrefixes);
8573
}
8674

8775
public static Builder builder() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private static Properties loadPropertiesFromClasspath() {
113113
.getResourceAsStream("prometheus.properties")) {
114114
properties.load(stream);
115115
} catch (Exception ignored) {
116+
// No properties file found on the classpath.
116117
}
117118
return properties;
118119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static Map<String, String> loadMap(String name, Map<Object, Object> properties)
9191
if (keyValue.length == 2) {
9292
String key = keyValue[0].trim();
9393
String value = keyValue[1].trim();
94-
if (key.length() > 0 && value.length() > 0) {
94+
if (!key.isEmpty() && !value.isEmpty()) {
9595
result.putIfAbsent(key, value);
9696
}
9797
}

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/datapoints/DistributionDataPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface DistributionDataPoint extends DataPoint, TimerApi {
2525
/** Observe {@code value}, and create a custom exemplar with the given labels. */
2626
void observeWithExemplar(double value, Labels labels);
2727

28-
/** {@inheritDoc} */
28+
@Override
2929
default Timer startTimer() {
3030
return new Timer(this::observe);
3131
}

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/datapoints/GaugeDataPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ default void decWithExemplar(double amount, Labels labels) {
5656
/** Set the gauge to {@code value}, and create a custom exemplar with the given labels. */
5757
void setWithExemplar(double value, Labels labels);
5858

59-
/** {@inheritDoc} */
59+
@Override
6060
default Timer startTimer() {
6161
return new Timer(this::set);
6262
}

0 commit comments

Comments
 (0)