Skip to content

Commit d530e64

Browse files
authored
Resolve BadImport from Error Prone (#6154)
Signed-off-by: Johnny Lim <[email protected]>
1 parent b4c3d06 commit d530e64

File tree

24 files changed

+112
-124
lines changed

24 files changed

+112
-124
lines changed

implementations/micrometer-registry-azure-monitor/src/test/java/io/micrometer/azuremonitor/AzureMonitorNamingConventionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.micrometer.azuremonitor;
1717

18-
import io.micrometer.core.instrument.Meter.Type;
18+
import io.micrometer.core.instrument.Meter;
1919
import org.junit.jupiter.api.Test;
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
@@ -26,7 +26,7 @@ class AzureMonitorNamingConventionTest {
2626

2727
@Test
2828
void testNameContainsDesiredCharacters() {
29-
assertThat(namingConvention.name("{[email protected]}", Type.GAUGE)).isEqualTo("_custom_Metric_1_");
29+
assertThat(namingConvention.name("{[email protected]}", Meter.Type.GAUGE)).isEqualTo("_custom_Metric_1_");
3030
}
3131

3232
@Test

implementations/micrometer-registry-new-relic/src/test/java/io/micrometer/newrelic/NewRelicNamingConventionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.micrometer.newrelic;
1717

18-
import io.micrometer.core.instrument.Meter.Type;
18+
import io.micrometer.core.instrument.Meter;
1919
import org.junit.jupiter.api.Test;
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
@@ -35,13 +35,13 @@ class NewRelicNamingConventionTest {
3535

3636
@Test
3737
void name() {
38-
String validString = newRelicNamingConvention.name(VALID_NAME, Type.COUNTER);
38+
String validString = newRelicNamingConvention.name(VALID_NAME, Meter.Type.COUNTER);
3939
assertThat(validString).isEqualTo(VALID_NAME);
4040
}
4141

4242
@Test
4343
void nameShouldStripInvalidCharacters() {
44-
String validString = newRelicNamingConvention.name(INVALID_NAME, Type.COUNTER);
44+
String validString = newRelicNamingConvention.name(INVALID_NAME, Meter.Type.COUNTER);
4545
assertThat(validString).isEqualTo("invalid_name");
4646
}
4747

implementations/micrometer-registry-prometheus/src/test/java/io/micrometer/prometheusmetrics/PrometheusMeterRegistryIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.sun.net.httpserver.HttpServer;
1919
import io.micrometer.common.lang.Nullable;
2020
import io.micrometer.core.instrument.*;
21-
import io.micrometer.core.instrument.Meter.Type;
2221
import io.micrometer.core.instrument.binder.jvm.JvmInfoMetrics;
2322
import io.prometheus.metrics.model.registry.PrometheusRegistry;
2423
import io.prometheus.metrics.tracer.common.SpanContext;
@@ -157,7 +156,7 @@ private void recordMetrics() {
157156
final int value = i;
158157
measurements.add(new Measurement(() -> value + 10, Statistic.values()[i]));
159158
}
160-
Meter.builder("test.custom", Type.OTHER, measurements).register(registry);
159+
Meter.builder("test.custom", Meter.Type.OTHER, measurements).register(registry);
161160
}
162161

163162
private void verifyBuildInfo() {

implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/internal/FlavorStatsdLineBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
import java.util.Objects;
2626
import java.util.stream.Collectors;
27-
28-
import static java.util.stream.Stream.of;
27+
import java.util.stream.Stream;
2928

3029
public abstract class FlavorStatsdLineBuilder implements StatsdLineBuilder {
3130

@@ -70,8 +69,8 @@ public String timing(double timeMs) {
7069

7170
protected String tags(@Nullable Statistic stat, @Nullable String otherTags, String keyValueSeparator,
7271
String preamble) {
73-
String tags = of(stat == null ? null : "statistic" + keyValueSeparator + stat.getTagValueRepresentation(),
74-
otherTags)
72+
String tags = Stream
73+
.of(stat == null ? null : "statistic" + keyValueSeparator + stat.getTagValueRepresentation(), otherTags)
7574
.filter(Objects::nonNull)
7675
.collect(Collectors.joining(","));
7776

implementations/micrometer-registry-wavefront/src/main/java/io/micrometer/wavefront/WavefrontConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.micrometer.wavefront;
1717

1818
import com.wavefront.sdk.common.clients.service.token.TokenService;
19-
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
2019
import io.micrometer.common.lang.Nullable;
2120
import io.micrometer.core.instrument.config.validate.InvalidReason;
2221
import io.micrometer.core.instrument.config.validate.Validated;
@@ -120,10 +119,12 @@ default String source() {
120119
*/
121120
default TokenService.Type apiTokenType() {
122121
return getEnum(this, TokenService.Type.class, "apiTokenType")
123-
.invalidateWhen(tokenType -> tokenType == Type.NO_TOKEN && WavefrontMeterRegistry.isDirectToApi(this),
122+
.invalidateWhen(
123+
tokenType -> tokenType == TokenService.Type.NO_TOKEN && WavefrontMeterRegistry.isDirectToApi(this),
124124
"must be set to something else whenever publishing directly to the Wavefront API",
125125
InvalidReason.MISSING)
126-
.orElse(WavefrontMeterRegistry.isDirectToApi(this) ? Type.WAVEFRONT_API_TOKEN : Type.NO_TOKEN);
126+
.orElse(WavefrontMeterRegistry.isDirectToApi(this) ? TokenService.Type.WAVEFRONT_API_TOKEN
127+
: TokenService.Type.NO_TOKEN);
127128
}
128129

129130
/**

implementations/micrometer-registry-wavefront/src/test/java/io/micrometer/wavefront/WavefrontConfigTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.micrometer.wavefront;
1717

18-
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
18+
import com.wavefront.sdk.common.clients.service.token.TokenService;
1919
import io.micrometer.core.Issue;
2020
import io.micrometer.core.instrument.config.validate.ValidationException;
2121
import org.junit.jupiter.api.Test;
@@ -52,7 +52,7 @@ void noExceptionAndNoTokenTypeIfTokenMissingButProxyUsed() {
5252
Map<String, String> wavefrontProps = Map.of("wavefront.uri", "proxy://example.org:2878");
5353
WavefrontConfig config = wavefrontProps::get;
5454
assertThatCode(config::apiToken).doesNotThrowAnyException();
55-
assertThat(config.apiTokenType()).isSameAs(Type.NO_TOKEN);
55+
assertThat(config.apiTokenType()).isSameAs(TokenService.Type.NO_TOKEN);
5656
}
5757

5858
@Test
@@ -61,7 +61,7 @@ void noExceptionAndWavefrontTokenTypeIfTokenPresentAndDirectAccessUsed() {
6161
"s3cr3t");
6262
WavefrontConfig config = wavefrontProps::get;
6363
assertThatCode(config::apiToken).doesNotThrowAnyException();
64-
assertThat(config.apiTokenType()).isSameAs(Type.WAVEFRONT_API_TOKEN);
64+
assertThat(config.apiTokenType()).isSameAs(TokenService.Type.WAVEFRONT_API_TOKEN);
6565
}
6666

6767
@Test
@@ -77,7 +77,7 @@ void apiTokenFailsIfNoTokenPresentAndDirectAccessUsed() {
7777
@Test
7878
void apiTokenTypeFailsIfNoTokenTypeAndDirectAccessUsed() {
7979
Map<String, String> wavefrontProps = Map.of("wavefront.uri", "https://example.org:2878",
80-
"wavefront.apiTokenType", Type.NO_TOKEN.name());
80+
"wavefront.apiTokenType", TokenService.Type.NO_TOKEN.name());
8181
WavefrontConfig config = wavefrontProps::get;
8282
assertThatCode(config::apiTokenType).isExactlyInstanceOf(ValidationException.class)
8383
.hasNoCause()
@@ -88,9 +88,9 @@ void apiTokenTypeFailsIfNoTokenTypeAndDirectAccessUsed() {
8888
@Test
8989
void apiTokenTypeShouldBeUsedIfDirectAccessUsed() {
9090
Map<String, String> wavefrontProps = Map.of("wavefront.uri", "https://example.org:2878",
91-
"wavefront.apiTokenType", Type.CSP_API_TOKEN.name());
91+
"wavefront.apiTokenType", TokenService.Type.CSP_API_TOKEN.name());
9292
WavefrontConfig config = wavefrontProps::get;
93-
assertThat(config.apiTokenType()).isSameAs(Type.CSP_API_TOKEN);
93+
assertThat(config.apiTokenType()).isSameAs(TokenService.Type.CSP_API_TOKEN);
9494
}
9595

9696
}

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

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
2121
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
2222
import io.micrometer.core.annotation.Incubating;
23-
import io.micrometer.core.instrument.Meter.Id;
2423
import io.micrometer.core.instrument.config.MeterFilter;
2524
import io.micrometer.core.instrument.config.MeterFilterReply;
2625
import io.micrometer.core.instrument.config.NamingConvention;
@@ -102,35 +101,36 @@ public abstract class MeterRegistry {
102101
* supported. Hence, we use CHM to support that iteration without
103102
* ConcurrentModificationException risk.
104103
*/
105-
private final Map<Id, Meter> meterMap = new ConcurrentHashMap<>();
104+
private final Map<Meter.Id, Meter> meterMap = new ConcurrentHashMap<>();
106105

107106
/**
108107
* write/remove guarded by meterMapLock, read in
109-
* {@link #getOrCreateMeter(DistributionStatisticConfig, BiFunction, Id, Function)} is
110-
* unguarded
108+
* {@link #getOrCreateMeter(DistributionStatisticConfig, BiFunction, Meter.Id, Function)}
109+
* is unguarded
111110
*/
112-
private final Map<Id, Meter> preFilterIdToMeterMap = new HashMap<>();
111+
private final Map<Meter.Id, Meter> preFilterIdToMeterMap = new HashMap<>();
113112

114113
/**
115114
* For reverse looking up pre-filter ID in {@link #preFilterIdToMeterMap} from the
116-
* Meter being removed in {@link #remove(Id)}. Guarded by the {@link #meterMapLock}.
115+
* Meter being removed in {@link #remove(Meter.Id)}. Guarded by the
116+
* {@link #meterMapLock}.
117117
*/
118-
private final Map<Meter, Id> meterToPreFilterIdMap = new HashMap<>();
118+
private final Map<Meter, Meter.Id> meterToPreFilterIdMap = new HashMap<>();
119119

120120
/**
121121
* Only needed when MeterFilter configured after Meters registered. Write/remove
122-
* guarded by meterMapLock, remove in {@link #unmarkStaleId(Id)} and other operations
123-
* unguarded
122+
* guarded by meterMapLock, remove in {@link #unmarkStaleId(Meter.Id)} and other
123+
* operations unguarded
124124
*/
125-
private final Set<Id> stalePreFilterIds = new HashSet<>();
125+
private final Set<Meter.Id> stalePreFilterIds = new HashSet<>();
126126

127127
/**
128128
* Map of meter id whose associated meter contains synthetic counterparts to those
129129
* synthetic ids. We maintain these associations so that when we remove a meter with
130130
* synthetics, they can removed as well.
131131
*/
132132
// Guarded by meterMapLock for both reads and writes
133-
private final Map<Id, Set<Id>> syntheticAssociations = new HashMap<>();
133+
private final Map<Meter.Id, Set<Meter.Id>> syntheticAssociations = new HashMap<>();
134134

135135
private final AtomicBoolean closed = new AtomicBoolean();
136136

@@ -255,7 +255,7 @@ protected <T> TimeGauge newTimeGauge(Meter.Id id, @Nullable T obj, TimeUnit valu
255255

256256
return new TimeGauge() {
257257
@Override
258-
public Id getId() {
258+
public Meter.Id getId() {
259259
return withUnit;
260260
}
261261

@@ -298,7 +298,7 @@ protected abstract <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLong
298298
* measurement.
299299
* @return A new function counter.
300300
*/
301-
protected abstract <T> FunctionCounter newFunctionCounter(Id id, T obj, ToDoubleFunction<T> countFunction);
301+
protected abstract <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, ToDoubleFunction<T> countFunction);
302302

303303
protected List<Tag> getConventionTags(Meter.Id id) {
304304
return id.getConventionTags(config().namingConvention());
@@ -622,28 +622,28 @@ private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.
622622
return meterClass.cast(m);
623623
}
624624

625-
private Id getMappedId(Id id) {
625+
private Meter.Id getMappedId(Meter.Id id) {
626626
if (id.syntheticAssociation() != null) {
627627
return id;
628628
}
629-
Id mappedId = id;
629+
Meter.Id mappedId = id;
630630
for (MeterFilter filter : filters) {
631631
mappedId = filter.map(mappedId);
632632
}
633633
return mappedId;
634634
}
635635

636636
private Meter getOrCreateMeter(@Nullable DistributionStatisticConfig config,
637-
BiFunction<Id, /* Nullable Generic */ DistributionStatisticConfig, ? extends Meter> builder, Id originalId,
638-
Function<Meter.Id, ? extends Meter> noopBuilder) {
637+
BiFunction<Meter.Id, /* Nullable Generic */ DistributionStatisticConfig, ? extends Meter> builder,
638+
Meter.Id originalId, Function<Meter.Id, ? extends Meter> noopBuilder) {
639639

640640
Meter m = preFilterIdToMeterMap.get(originalId);
641641
if (m != null && !isStaleId(originalId)) {
642642
checkAndWarnAboutDoubleRegistration(m);
643643
return m;
644644
}
645645

646-
Id mappedId = getMappedId(originalId);
646+
Meter.Id mappedId = getMappedId(originalId);
647647
m = meterMap.get(mappedId);
648648

649649
if (m != null) {
@@ -678,9 +678,10 @@ private Meter getOrCreateMeter(@Nullable DistributionStatisticConfig config,
678678

679679
m = builder.apply(mappedId, config);
680680

681-
Id synAssoc = mappedId.syntheticAssociation();
681+
Meter.Id synAssoc = mappedId.syntheticAssociation();
682682
if (synAssoc != null) {
683-
Set<Id> associations = syntheticAssociations.computeIfAbsent(synAssoc, k -> new HashSet<>());
683+
Set<Meter.Id> associations = syntheticAssociations.computeIfAbsent(synAssoc,
684+
k -> new HashSet<>());
684685
associations.add(mappedId);
685686
}
686687

@@ -698,7 +699,7 @@ private Meter getOrCreateMeter(@Nullable DistributionStatisticConfig config,
698699
return m;
699700
}
700701

701-
private boolean isStaleId(Id originalId) {
702+
private boolean isStaleId(Meter.Id originalId) {
702703
return !stalePreFilterIds.isEmpty() && stalePreFilterIds.contains(originalId);
703704
}
704705

@@ -707,7 +708,7 @@ private boolean isStaleId(Id originalId) {
707708
* @param originalId id before any filter mapping has been applied
708709
* @return {@code true} if the id is stale
709710
*/
710-
private boolean unmarkStaleId(Id originalId) {
711+
private boolean unmarkStaleId(Meter.Id originalId) {
711712
return !stalePreFilterIds.isEmpty() && stalePreFilterIds.remove(originalId);
712713
}
713714

@@ -743,8 +744,8 @@ else if (reply == MeterFilterReply.ACCEPT) {
743744

744745
/**
745746
* Remove a {@link Meter} from this {@link MeterRegistry registry}. This is expected
746-
* to be a {@link Meter} with the same {@link Id} returned when registering a meter -
747-
* which will have {@link MeterFilter}s applied to it.
747+
* to be a {@link Meter} with the same {@link Meter.Id} returned when registering a
748+
* meter - which will have {@link MeterFilter}s applied to it.
748749
* @param meter The meter to remove
749750
* @return The removed meter, or null if the provided meter is not currently
750751
* registered.
@@ -758,8 +759,8 @@ public Meter remove(Meter meter) {
758759

759760
/**
760761
* Remove a {@link Meter} from this {@link MeterRegistry registry} based on its
761-
* {@link Id} before applying this registry's {@link MeterFilter}s to the given
762-
* {@link Id}.
762+
* {@link Meter.Id} before applying this registry's {@link MeterFilter}s to the given
763+
* {@link Meter.Id}.
763764
* @param preFilterId the id of the meter to remove
764765
* @return The removed meter, or null if the meter is not found
765766
* @since 1.3.16
@@ -775,9 +776,9 @@ public Meter removeByPreFilterId(Meter.Id preFilterId) {
775776

776777
/**
777778
* Remove a {@link Meter} from this {@link MeterRegistry registry} based the given
778-
* {@link Id} as-is. The registry's {@link MeterFilter}s will not be applied to it.
779-
* You can use the {@link Id} of the {@link Meter} returned when registering a meter,
780-
* since that will have {@link MeterFilter}s already applied to it.
779+
* {@link Meter.Id} as-is. The registry's {@link MeterFilter}s will not be applied to
780+
* it. You can use the {@link Meter.Id} of the {@link Meter} returned when registering
781+
* a meter, since that will have {@link MeterFilter}s already applied to it.
781782
* @param mappedId The id of the meter to remove
782783
* @return The removed meter, or null if no meter matched the provided id.
783784
* @since 1.1.0
@@ -789,13 +790,13 @@ public Meter remove(Meter.Id mappedId) {
789790
synchronized (meterMapLock) {
790791
final Meter removedMeter = meterMap.remove(mappedId);
791792
if (removedMeter != null) {
792-
Id preFilterIdToRemove = meterToPreFilterIdMap.remove(removedMeter);
793+
Meter.Id preFilterIdToRemove = meterToPreFilterIdMap.remove(removedMeter);
793794
preFilterIdToMeterMap.remove(preFilterIdToRemove);
794795
stalePreFilterIds.remove(preFilterIdToRemove);
795796

796-
Set<Id> synthetics = syntheticAssociations.remove(mappedId);
797+
Set<Meter.Id> synthetics = syntheticAssociations.remove(mappedId);
797798
if (synthetics != null) {
798-
for (Id synthetic : synthetics) {
799+
for (Meter.Id synthetic : synthetics) {
799800
remove(synthetic);
800801
}
801802
}
@@ -913,7 +914,7 @@ public Config onMeterRemoved(Consumer<Meter> meterRemovedListener) {
913914
* @since 1.6.0
914915
*/
915916
@Incubating(since = "1.6.0")
916-
public Config onMeterRegistrationFailed(BiConsumer<Id, String> meterRegistrationFailedListener) {
917+
public Config onMeterRegistrationFailed(BiConsumer<Meter.Id, String> meterRegistrationFailedListener) {
917918
meterRegistrationFailedListeners.add(meterRegistrationFailedListener);
918919
return this;
919920
}
@@ -1213,23 +1214,23 @@ public boolean isClosed() {
12131214
* @since 1.6.0
12141215
*/
12151216
protected void meterRegistrationFailed(Meter.Id id, @Nullable String reason) {
1216-
for (BiConsumer<Id, String> listener : meterRegistrationFailedListeners) {
1217+
for (BiConsumer<Meter.Id, String> listener : meterRegistrationFailedListeners) {
12171218
listener.accept(id, reason);
12181219
}
12191220
}
12201221

12211222
// VisibleForTesting
1222-
Map<Id, Meter> _getPreFilterIdToMeterMap() {
1223+
Map<Meter.Id, Meter> _getPreFilterIdToMeterMap() {
12231224
return Collections.unmodifiableMap(preFilterIdToMeterMap);
12241225
}
12251226

12261227
// VisibleForTesting
1227-
Map<Meter, Id> _getMeterToPreFilterIdMap() {
1228+
Map<Meter, Meter.Id> _getMeterToPreFilterIdMap() {
12281229
return Collections.unmodifiableMap(meterToPreFilterIdMap);
12291230
}
12301231

12311232
// VisibleForTesting
1232-
Set<Id> _getStalePreFilterIds() {
1233+
Set<Meter.Id> _getStalePreFilterIds() {
12331234
return Collections.unmodifiableSet(stalePreFilterIds);
12341235
}
12351236

0 commit comments

Comments
 (0)