Skip to content

Commit 6a69b29

Browse files
committed
Configure Errorprone in build
Also fixes ERROR severity bug patterns.
1 parent 2df92cf commit 6a69b29

File tree

19 files changed

+60
-44
lines changed

19 files changed

+60
-44
lines changed

build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11+
classpath libs.plugin.errorprone
1112
classpath libs.plugin.license
1213
classpath libs.plugin.nebulaRelease
1314
classpath libs.plugin.nebulaPublishing
@@ -61,6 +62,7 @@ allprojects {
6162
}
6263

6364
subprojects {
65+
apply plugin: 'net.ltgt.errorprone'
6466
apply plugin: 'signing'
6567
apply plugin: 'io.spring.javaformat'
6668
apply plugin: 'com.diffplug.spotless'
@@ -103,6 +105,7 @@ subprojects {
103105
// JSR-305 only used for non-required meta-annotations
104106
optionalApi libs.jsr305
105107
checkstyle libs.spring.javaformatCheckstyle
108+
errorprone(libs.errorprone)
106109
}
107110

108111
tasks {

gradle/libs.versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ dropwizardMetricsCore5 = { module = "io.dropwizard.metrics5:metrics-core", versi
102102
dynatraceUtils = { module = "com.dynatrace.metric.util:dynatrace-metric-utils-java", version.ref = "dynatrace-utils" }
103103
ehcache2 = { module = "net.sf.ehcache:ehcache", version.ref = "ehcache2" }
104104
ehcache3 = { module = "org.ehcache:ehcache", version.ref = "ehcache3" }
105+
errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.37.0" }
105106
felixFramework = "org.apache.felix:org.apache.felix.framework:7.0.5"
106107
felixScr = "org.apache.felix:org.apache.felix.scr:2.2.12"
107108
gmetric4j = { module = "info.ganglia.gmetric4j:gmetric4j", version.ref = "gmetric4j" }
@@ -213,6 +214,7 @@ wiremock = { module = "com.github.tomakehurst:wiremock-jre8-standalone", version
213214
wiremockJunit5 = { module = "ru.lanwen.wiremock:wiremock-junit5", version.ref = "wiremock-junit5" }
214215

215216
# plugin dependencies
217+
plugin-errorprone = { module = "net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin", version = "4.1.0" }
216218
plugin-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version = "0.16.1" }
217219
plugin-nebulaRelease = { module = "com.netflix.nebula:nebula-release-plugin", version = "18.0.8" }
218220
plugin-nebulaPublishing = { module = "com.netflix.nebula:nebula-publishing-plugin", version = "20.3.0" }

implementations/micrometer-registry-elastic/src/main/java/io/micrometer/elastic/ElasticConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ default String index() {
7676
* separated by the {@link #indexDateSeparator()}. Default is: "yyyy-MM"
7777
* @return date format for index
7878
*/
79+
@SuppressWarnings("ReturnValueIgnored")
7980
default String indexDateFormat() {
8081
return getString(this, "indexDateFormat").invalidateWhen(format -> {
8182
if (format == null) {
@@ -178,6 +179,7 @@ default String documentType() {
178179
return getString(this, "documentType").orElse("doc");
179180
}
180181

182+
@SuppressWarnings("ReturnValueIgnored")
181183
@Override
182184
default Validated<?> validate() {
183185
return checkAll(this, c -> StepRegistryConfig.validate(c), checkRequired("host", ElasticConfig::host),

micrometer-core/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ java11Test {
283283
}
284284

285285
compileJava11TestJava {
286+
options.errorprone.enabled = false
286287
sourceCompatibility = JavaVersion.VERSION_11
287288
targetCompatibility = JavaVersion.VERSION_11
288289
}
290+
291+
compileJava11Java {
292+
options.errorprone.enabled = false
293+
}

micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ private void record(ProceedingJoinPoint pjp, Timed timed, String metricName, Tim
274274

275275
private Timer.Builder recordBuilder(ProceedingJoinPoint pjp, Timed timed, String metricName,
276276
String exceptionClass) {
277+
@SuppressWarnings("NullTernary")
277278
Timer.Builder builder = Timer.builder(metricName)
278279
.description(timed.description().isEmpty() ? null : timed.description())
279280
.tags(timed.extraTags())

micrometer-core/src/main/java/io/micrometer/core/instrument/Timer.java

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static ResourceSample resource(MeterRegistry registry, String name) {
8989
* empty.
9090
* @return This builder.
9191
*/
92+
@SuppressWarnings("NullTernary")
9293
static Builder builder(Timed timed, String defaultName) {
9394
if (timed.longTask() && timed.value().isEmpty()) {
9495
// the user MUST name long task timers, we don't lump them in with regular

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/grpc/AbstractMetricCollectingInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected Function<Code, Timer> asTimerFunction(final Supplier<Timer.Builder> ti
205205
final Function<Code, Timer> cacheResolver = code -> cache.computeIfAbsent(code, creator);
206206
// Eager initialize
207207
for (final Code code : this.eagerInitializedCodes) {
208-
cacheResolver.apply(code);
208+
Timer ignored = cacheResolver.apply(code);
209209
}
210210
return cacheResolver;
211211
}

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmGcMetrics.java

+27-27
Original file line numberDiff line numberDiff line change
@@ -339,33 +339,33 @@ enum GcGenerationAge {
339339

340340
OLD, YOUNG, UNKNOWN;
341341

342-
private static final Map<String, GcGenerationAge> knownCollectors = new HashMap<String, GcGenerationAge>() {
343-
{
344-
put("ConcurrentMarkSweep", OLD);
345-
put("Copy", YOUNG);
346-
put("G1 Old Generation", OLD);
347-
put("G1 Young Generation", YOUNG);
348-
put("MarkSweepCompact", OLD);
349-
put("PS MarkSweep", OLD);
350-
put("PS Scavenge", YOUNG);
351-
put("ParNew", YOUNG);
352-
put("global", OLD);
353-
put("scavenge", YOUNG);
354-
put("partial gc", YOUNG);
355-
put("global garbage collect", OLD);
356-
put("Epsilon", OLD);
357-
// GPGC (Azul's C4, see:
358-
// https://docs.azul.com/prime/release-notes#prime_stream_22_12_0_0)
359-
put("GPGC New", YOUNG); // old naming
360-
put("GPGC Old", OLD); // old naming
361-
put("GPGC New Cycles", YOUNG); // new naming
362-
put("GPGC Old Cycles", OLD); // new naming
363-
put("GPGC New Pauses", YOUNG); // new naming
364-
put("GPGC Old Pauses", OLD); // new naming
365-
put("ZGC Major Cycles", OLD); // do not include 'ZGC Major Pauses'; see
366-
// gh-2872
367-
}
368-
};
342+
private static final Map<String, GcGenerationAge> knownCollectors = new HashMap<>();
343+
344+
static {
345+
knownCollectors.put("ConcurrentMarkSweep", OLD);
346+
knownCollectors.put("Copy", YOUNG);
347+
knownCollectors.put("G1 Old Generation", OLD);
348+
knownCollectors.put("G1 Young Generation", YOUNG);
349+
knownCollectors.put("MarkSweepCompact", OLD);
350+
knownCollectors.put("PS MarkSweep", OLD);
351+
knownCollectors.put("PS Scavenge", YOUNG);
352+
knownCollectors.put("ParNew", YOUNG);
353+
knownCollectors.put("global", OLD);
354+
knownCollectors.put("scavenge", YOUNG);
355+
knownCollectors.put("partial gc", YOUNG);
356+
knownCollectors.put("global garbage collect", OLD);
357+
knownCollectors.put("Epsilon", OLD);
358+
// GPGC (Azul's C4, see:
359+
// https://docs.azul.com/prime/release-notes#prime_stream_22_12_0_0)
360+
knownCollectors.put("GPGC New", YOUNG); // old naming
361+
knownCollectors.put("GPGC Old", OLD); // old naming
362+
knownCollectors.put("GPGC New Cycles", YOUNG); // new naming
363+
knownCollectors.put("GPGC Old Cycles", OLD); // new naming
364+
knownCollectors.put("GPGC New Pauses", YOUNG); // new naming
365+
knownCollectors.put("GPGC Old Pauses", OLD); // new naming
366+
// do not include 'ZGC Major Pauses'; see gh-2872
367+
knownCollectors.put("ZGC Major Cycles", OLD);
368+
}
369369

370370
static GcGenerationAge fromGcName(String gcName) {
371371
return knownCollectors.getOrDefault(gcName, UNKNOWN);

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/system/FileDescriptorMetrics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private Method detectMethod(String name) {
123123
}
124124
try {
125125
// ensure the Bean we have is actually an instance of the interface
126-
osBeanClass.cast(osBean);
126+
Object ignored = osBeanClass.cast(osBean);
127127
return osBeanClass.getDeclaredMethod(name);
128128
}
129129
catch (ClassCastException | NoSuchMethodException | SecurityException e) {

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/system/ProcessorMetrics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private Method detectMethod(String name) {
150150
}
151151
try {
152152
// ensure the Bean we have is actually an instance of the interface
153-
operatingSystemBeanClass.cast(operatingSystemBean);
153+
Object ignored = operatingSystemBeanClass.cast(operatingSystemBean);
154154
return operatingSystemBeanClass.getMethod(name);
155155
}
156156
catch (ClassCastException | NoSuchMethodException | SecurityException e) {

micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/FixedBoundaryVictoriaMetricsHistogram.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private void outputSummary(PrintStream printStream, double bucketScaling) {
251251
printStream.format("%14s %10s\n\n", "Bucket", "TotalCount");
252252

253253
for (CountAtBucket bucket : nonZeroBuckets()) {
254-
printStream.format(Locale.US, "%14.1f %10d\n", bucket.bucket() / bucketScaling, bucket.count());
254+
printStream.format(Locale.US, "%14.1f %10f\n", bucket.bucket() / bucketScaling, bucket.count());
255255
}
256256

257257
printStream.write('\n');

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/jetty/InstrumentedQueuedThreadPoolTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.junit.jupiter.api.Test;
2626

2727
import java.util.Arrays;
28-
import java.util.function.BiFunction;
28+
import java.util.function.BiConsumer;
2929
import java.util.stream.Collectors;
3030

3131
import static org.assertj.core.api.Assertions.assertThat;
@@ -89,8 +89,8 @@ private void assertThatMetricsDoNotExist(MeterRegistry meterRegistry) {
8989
}
9090

9191
private void assertThatMetrics(MeterRegistry meterRegistry,
92-
BiFunction<Iterable<String>, ListAssert<String>, ListAssert<String>> assertFunction) {
93-
assertFunction.apply(
92+
BiConsumer<Iterable<String>, ListAssert<String>> assertConsumer) {
93+
assertConsumer.accept(
9494
Arrays.asList("jetty.threads.jobs", "jetty.threads.busy", "jetty.threads.idle",
9595
"jetty.threads.config.max", "jetty.threads.config.min", "jetty.threads.current"),
9696
assertThat(

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/jvm/JvmMemoryMetricsTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ private void assertJvmMemoryMetrics(MeterRegistry registry, String area) {
4848
assertThat(memUsed.getId().getBaseUnit()).isEqualTo(BaseUnits.BYTES);
4949

5050
Gauge memCommitted = registry.get("jvm.memory.committed").tags("area", area).gauge();
51-
assertThat(memCommitted.value()).isNotNull();
51+
assertThat(memCommitted.value()).isNotNaN();
5252
assertThat(memCommitted.getId().getBaseUnit()).isEqualTo(BaseUnits.BYTES);
5353

5454
Gauge memMax = registry.get("jvm.memory.max").tags("area", area).gauge();
55-
assertThat(memMax.value()).isNotNull();
55+
assertThat(memMax.value()).isNotNaN();
5656
assertThat(memMax.getId().getBaseUnit()).isEqualTo(BaseUnits.BYTES);
5757
}
5858

5959
private void assertJvmBufferMetrics(MeterRegistry registry, String bufferId) {
6060
assertThat(registry.get("jvm.buffer.count").tags("id", bufferId).gauge().value()).isGreaterThanOrEqualTo(0);
6161

6262
Gauge memoryUsedDirect = registry.get("jvm.buffer.memory.used").tags("id", bufferId).gauge();
63-
assertThat(memoryUsedDirect.value()).isNotNull();
63+
assertThat(memoryUsedDirect.value()).isNotNaN();
6464
assertThat(memoryUsedDirect.getId().getBaseUnit()).isEqualTo(BaseUnits.BYTES);
6565

6666
Gauge bufferTotal = registry.get("jvm.buffer.total.capacity").tags("id", bufferId).gauge();

micrometer-core/src/test/java/io/micrometer/core/instrument/distribution/TimeWindowMaxTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ void testLongPeriodOfInactivity() {
7171

7272
@Test
7373
void throwsExceptionWhenRotateFrequency0() {
74-
assertThatThrownBy(() -> new TimeWindowMax(clock, 0, 3)).isInstanceOf(IllegalArgumentException.class)
75-
.withFailMessage("Rotate frequency must be a positive number");
74+
assertThatThrownBy(() -> new TimeWindowMax(clock, 0, 3))
75+
.withFailMessage("Rotate frequency must be a positive number")
76+
.isInstanceOf(IllegalArgumentException.class);
7677
}
7778

7879
}

micrometer-core/src/test/java/io/micrometer/core/instrument/step/StepMeterRegistryTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ protected void publish() {
657657
prePublishAction.run();
658658
}
659659
publishCount.incrementAndGet();
660-
getMeters().stream()
660+
List<Meter> ignored = getMeters().stream()
661661
.map(meter -> meter.match(g -> null, this::publishCounter, this::publishTimer, this::publishSummary,
662662
null, tg -> null, this::publishFunctionCounter, this::publishFunctionTimer, m -> null))
663663
.collect(Collectors.toList());

micrometer-observation-test/src/main/java/io/micrometer/observation/tck/TestObservationRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public boolean equals(Object o) {
122122
if (this == o) {
123123
return true;
124124
}
125-
if (o == null || getClass() != o.getClass()) {
125+
if (!(o instanceof TestObservationContext)) {
126126
return false;
127127
}
128128
TestObservationContext that = (TestObservationContext) o;

micrometer-observation-test/src/main/java/io/micrometer/observation/tck/TestObservationRegistryAssert.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public TestObservationRegistryAssert hasNumberOfObservationsWithNameEqualToIgnor
332332
*/
333333
public TestObservationRegistryAssert hasAnObservationWithAKeyValue(String key, String value) {
334334
isNotNull();
335-
this.actual.getContexts()
335+
KeyValue ignored = this.actual.getContexts()
336336
.stream()
337337
.flatMap(f -> f.getContext().getAllKeyValues().stream())
338338
.filter(keyValue -> keyValue.getKey().equals(key) && keyValue.getValue().equals(value))
@@ -381,7 +381,7 @@ public TestObservationRegistryAssert hasAnObservationWithAKeyValue(KeyValue keyV
381381
*/
382382
public TestObservationRegistryAssert hasAnObservationWithAKeyName(String key) {
383383
isNotNull();
384-
this.actual.getContexts()
384+
KeyValue ignored = this.actual.getContexts()
385385
.stream()
386386
.flatMap(f -> f.getContext().getAllKeyValues().stream())
387387
.filter(keyValue -> keyValue.getKey().equals(key))

micrometer-test/src/test/java/io/micrometer/core/instrument/binder/cache/CaffeineCacheMetricsCompatibilityTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public CacheMeterBinder<LoadingCache<String, String>> binder() {
4141
return new CaffeineCacheMetrics<>(cache, "mycache", emptyList());
4242
}
4343

44+
@SuppressWarnings("CheckReturnValue")
4445
@Override
4546
public void put(String key, String value) {
4647
synchronized (this) {

samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public String get(String k) {
122122
os.close();
123123
});
124124

125-
new Thread(server::start).run();
125+
new Thread(server::start).start();
126126
}
127127
catch (IOException e) {
128128
throw new RuntimeException(e);

0 commit comments

Comments
 (0)