Skip to content

Commit e45501f

Browse files
Migrate micrometer-core to jSpecify (#6385)
Also fixes some nullability issues uncovered by NullAway. --------- Co-authored-by: Jonatan Ivanov <[email protected]>
1 parent e6a99c6 commit e45501f

File tree

218 files changed

+973
-1070
lines changed

Some content is hidden

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

218 files changed

+973
-1070
lines changed

docs/src/test/java/io/micrometer/docs/metrics/SpelValueExpressionResolver.java

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

1818
import io.micrometer.common.annotation.ValueExpressionResolver;
19-
import io.micrometer.common.lang.NonNull;
20-
import io.micrometer.common.lang.Nullable;
2119
import io.micrometer.common.util.internal.logging.InternalLogger;
2220
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
21+
import org.jspecify.annotations.NonNull;
22+
import org.jspecify.annotations.Nullable;
2323
import org.springframework.expression.Expression;
2424
import org.springframework.expression.ExpressionParser;
2525
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -29,9 +29,8 @@ class SpelValueExpressionResolver implements ValueExpressionResolver {
2929

3030
private static final InternalLogger log = InternalLoggerFactory.getInstance(SpelValueExpressionResolver.class);
3131

32-
@NonNull
3332
@Override
34-
public String resolve(@NonNull String expression, @Nullable Object parameter) {
33+
public @NonNull String resolve(@NonNull String expression, @Nullable Object parameter) {
3534
try {
3635
SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
3736
ExpressionParser expressionParser = new SpelExpressionParser();

implementations/micrometer-registry-statsd/src/test/java/io/micrometer/statsd/StatsdMeterRegistryPublishTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package io.micrometer.statsd;
1717

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.core.Issue;
2019
import io.micrometer.core.instrument.Clock;
2120
import io.micrometer.core.instrument.Counter;
@@ -25,6 +24,7 @@
2524
import io.netty.channel.unix.DomainSocketAddress;
2625
import io.netty.handler.logging.LogLevel;
2726
import io.netty.handler.logging.LoggingHandler;
27+
import org.jspecify.annotations.Nullable;
2828
import org.junit.jupiter.api.Test;
2929
import org.junit.jupiter.api.condition.OS;
3030
import org.junit.jupiter.params.ParameterizedTest;

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
package io.micrometer.core.aop;
1717

1818
import io.micrometer.common.KeyValue;
19-
import io.micrometer.common.lang.NonNullApi;
20-
import io.micrometer.common.lang.Nullable;
2119
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
2220
import io.micrometer.core.annotation.Counted;
2321
import io.micrometer.core.instrument.*;
2422
import org.aspectj.lang.ProceedingJoinPoint;
2523
import org.aspectj.lang.annotation.Around;
2624
import org.aspectj.lang.annotation.Aspect;
2725
import org.aspectj.lang.reflect.MethodSignature;
26+
import org.jspecify.annotations.NullMarked;
27+
import org.jspecify.annotations.Nullable;
2828

2929
import java.lang.reflect.Method;
3030
import java.util.concurrent.CompletionStage;
@@ -77,7 +77,7 @@
7777
* @see Counted
7878
*/
7979
@Aspect
80-
@NonNullApi
80+
@NullMarked
8181
public class CountedAspect {
8282

8383
private static final WarnThenDebugLogger WARN_THEN_DEBUG_LOGGER = new WarnThenDebugLogger(CountedAspect.class);
@@ -116,7 +116,7 @@ public class CountedAspect {
116116
*/
117117
private final Predicate<ProceedingJoinPoint> shouldSkip;
118118

119-
private CountedMeterTagAnnotationHandler meterTagAnnotationHandler;
119+
private @Nullable CountedMeterTagAnnotationHandler meterTagAnnotationHandler;
120120

121121
/**
122122
* Creates a {@code CountedAspect} instance with {@link Metrics#globalRegistry}.
@@ -189,8 +189,7 @@ private Function<ProceedingJoinPoint, Iterable<Tag>> makeSafe(
189189
}
190190

191191
@Around("@within(io.micrometer.core.annotation.Counted) && !@annotation(io.micrometer.core.annotation.Counted) && execution(* *(..))")
192-
@Nullable
193-
public Object countedClass(ProceedingJoinPoint pjp) throws Throwable {
192+
public @Nullable Object countedClass(ProceedingJoinPoint pjp) throws Throwable {
194193
if (shouldSkip.test(pjp)) {
195194
return pjp.proceed();
196195
}
@@ -224,17 +223,15 @@ public Object countedClass(ProceedingJoinPoint pjp) throws Throwable {
224223
* @throws Throwable When the intercepted method throws one.
225224
*/
226225
@Around(value = "@annotation(counted) && execution(* *(..))", argNames = "pjp,counted")
227-
@Nullable
228-
public Object interceptAndRecord(ProceedingJoinPoint pjp, Counted counted) throws Throwable {
226+
public @Nullable Object interceptAndRecord(ProceedingJoinPoint pjp, Counted counted) throws Throwable {
229227
if (shouldSkip.test(pjp)) {
230228
return pjp.proceed();
231229
}
232230

233231
return perform(pjp, counted);
234232
}
235233

236-
@Nullable
237-
private Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwable {
234+
private @Nullable Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwable {
238235
final Method method = ((MethodSignature) pjp.getSignature()).getMethod();
239236
final boolean stopWhenCompleted = CompletionStage.class.isAssignableFrom(method.getReturnType());
240237

@@ -273,7 +270,7 @@ private Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwabl
273270
}
274271

275272
private void recordCompletionResult(ProceedingJoinPoint pjp, @Nullable Object methodResult, Counted counted,
276-
Throwable throwable) {
273+
@Nullable Throwable throwable) {
277274

278275
if (throwable != null) {
279276
String exceptionTagValue = throwable.getCause() == null ? throwable.getClass().getSimpleName()

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package io.micrometer.core.aop;
1717

1818
import io.micrometer.common.KeyValue;
19-
import io.micrometer.common.lang.NonNullApi;
20-
import io.micrometer.common.lang.Nullable;
2119
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
2220
import io.micrometer.core.annotation.Incubating;
2321
import io.micrometer.core.annotation.Timed;
@@ -27,6 +25,8 @@
2725
import org.aspectj.lang.annotation.Around;
2826
import org.aspectj.lang.annotation.Aspect;
2927
import org.aspectj.lang.reflect.MethodSignature;
28+
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
3030

3131
import java.lang.reflect.Method;
3232
import java.time.Duration;
@@ -87,7 +87,7 @@
8787
* @since 1.0.0
8888
*/
8989
@Aspect
90-
@NonNullApi
90+
@NullMarked
9191
@Incubating(since = "1.0.0")
9292
public class TimedAspect {
9393

@@ -112,7 +112,7 @@ public class TimedAspect {
112112

113113
private final Predicate<ProceedingJoinPoint> shouldSkip;
114114

115-
private MeterTagAnnotationHandler meterTagAnnotationHandler;
115+
private @Nullable MeterTagAnnotationHandler meterTagAnnotationHandler;
116116

117117
/**
118118
* Creates a {@code TimedAspect} instance with {@link Metrics#globalRegistry}.
@@ -185,8 +185,7 @@ private Function<ProceedingJoinPoint, Iterable<Tag>> makeSafe(
185185
}
186186

187187
@Around("@within(io.micrometer.core.annotation.Timed) && !@annotation(io.micrometer.core.annotation.Timed) && execution(* *(..))")
188-
@Nullable
189-
public Object timedClass(ProceedingJoinPoint pjp) throws Throwable {
188+
public @Nullable Object timedClass(ProceedingJoinPoint pjp) throws Throwable {
190189
if (shouldSkip.test(pjp)) {
191190
return pjp.proceed();
192191
}
@@ -202,8 +201,7 @@ public Object timedClass(ProceedingJoinPoint pjp) throws Throwable {
202201
}
203202

204203
@Around("execution (@io.micrometer.core.annotation.Timed * *.*(..))")
205-
@Nullable
206-
public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
204+
public @Nullable Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
207205
if (shouldSkip.test(pjp)) {
208206
return pjp.proceed();
209207
}
@@ -218,8 +216,7 @@ public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
218216
return perform(pjp, timed, method);
219217
}
220218

221-
@Nullable
222-
private Object perform(ProceedingJoinPoint pjp, Timed timed, Method method) throws Throwable {
219+
private @Nullable Object perform(ProceedingJoinPoint pjp, Timed timed, Method method) throws Throwable {
223220
final String metricName = timed.value().isEmpty() ? DEFAULT_METRIC_NAME : timed.value();
224221
final boolean stopWhenCompleted = CompletionStage.class.isAssignableFrom(method.getReturnType());
225222

@@ -231,9 +228,8 @@ private Object perform(ProceedingJoinPoint pjp, Timed timed, Method method) thro
231228
}
232229
}
233230

234-
@Nullable
235-
private Object processWithTimer(ProceedingJoinPoint pjp, Timed timed, String metricName, boolean stopWhenCompleted)
236-
throws Throwable {
231+
private @Nullable Object processWithTimer(ProceedingJoinPoint pjp, Timed timed, String metricName,
232+
boolean stopWhenCompleted) throws Throwable {
237233

238234
Timer.Sample sample = Timer.start(registry);
239235

@@ -303,7 +299,7 @@ private Timer.Builder recordBuilder(ProceedingJoinPoint pjp, @Nullable Object me
303299
return builder;
304300
}
305301

306-
private String getExceptionTag(Throwable throwable) {
302+
private String getExceptionTag(@Nullable Throwable throwable) {
307303

308304
if (throwable == null) {
309305
return DEFAULT_EXCEPTION_TAG_VALUE;
@@ -316,8 +312,7 @@ private String getExceptionTag(Throwable throwable) {
316312
return throwable.getCause().getClass().getSimpleName();
317313
}
318314

319-
@Nullable
320-
private Object processWithLongTaskTimer(ProceedingJoinPoint pjp, Timed timed, String metricName,
315+
private @Nullable Object processWithLongTaskTimer(ProceedingJoinPoint pjp, Timed timed, String metricName,
321316
boolean stopWhenCompleted) throws Throwable {
322317

323318
Optional<LongTaskTimer.Sample> sample = buildLongTaskTimer(pjp, timed, metricName).map(LongTaskTimer::start);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.micrometer.core.instrument;
1717

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.core.instrument.distribution.*;
19+
import org.jspecify.annotations.Nullable;
2020

2121
public abstract class AbstractDistributionSummary extends AbstractMeter implements DistributionSummary {
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.micrometer.core.instrument;
1717

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.core.instrument.util.MeterEquivalence;
19+
import org.jspecify.annotations.Nullable;
2020

2121
/**
2222
* Base class for {@link Meter} implementations.

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

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

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger;
2019
import io.micrometer.core.instrument.distribution.*;
2120
import io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector;
@@ -24,6 +23,7 @@
2423
import org.LatencyUtils.IntervalEstimator;
2524
import org.LatencyUtils.SimplePauseDetector;
2625
import org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator;
26+
import org.jspecify.annotations.Nullable;
2727

2828
import java.util.Map;
2929
import java.util.concurrent.Callable;
@@ -48,11 +48,9 @@ public abstract class AbstractTimer extends AbstractMeter implements Timer {
4848
private final TimeUnit baseTimeUnit;
4949

5050
// Only used when pause detection is enabled
51-
@Nullable
52-
private Object intervalEstimator;
51+
private @Nullable Object intervalEstimator;
5352

54-
@Nullable
55-
private org.LatencyUtils.PauseDetector pauseDetector;
53+
private org.LatencyUtils.@Nullable PauseDetector pauseDetector;
5654

5755
/**
5856
* Creates a new timer.

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

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

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
2019
import io.micrometer.core.instrument.distribution.pause.PauseDetector;
20+
import org.jspecify.annotations.Nullable;
2121

2222
import java.time.Duration;
2323
import java.util.Arrays;
@@ -38,11 +38,9 @@ public abstract class AbstractTimerBuilder<B extends AbstractTimerBuilder<B>> {
3838

3939
protected final DistributionStatisticConfig.Builder distributionConfigBuilder;
4040

41-
@Nullable
42-
protected String description;
41+
protected @Nullable String description;
4342

44-
@Nullable
45-
protected PauseDetector pauseDetector;
43+
protected @Nullable PauseDetector pauseDetector;
4644

4745
protected AbstractTimerBuilder(String name) {
4846
this.name = name;
@@ -89,7 +87,7 @@ public B tag(String key, String value) {
8987
* be expressed as {@code 0.95}.
9088
* @return This builder.
9189
*/
92-
public B publishPercentiles(@Nullable double... percentiles) {
90+
public B publishPercentiles(double @Nullable ... percentiles) {
9391
this.distributionConfigBuilder.percentiles(percentiles);
9492
return (B) this;
9593
}
@@ -145,7 +143,7 @@ public B publishPercentileHistogram(@Nullable Boolean enabled) {
145143
* are the threshold we intend to measure against, then.
146144
*/
147145
@Deprecated
148-
public B sla(@Nullable Duration... sla) {
146+
public B sla(Duration @Nullable ... sla) {
149147
return serviceLevelObjectives(sla);
150148
}
151149

@@ -160,7 +158,7 @@ public B sla(@Nullable Duration... sla) {
160158
* @return This builder.
161159
* @since 1.5.0
162160
*/
163-
public B serviceLevelObjectives(@Nullable Duration... slos) {
161+
public B serviceLevelObjectives(Duration @Nullable ... slos) {
164162
if (slos != null) {
165163
this.distributionConfigBuilder
166164
.serviceLevelObjectives(Arrays.stream(slos).mapToDouble(Duration::toNanos).toArray());

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

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

18-
import io.micrometer.common.lang.Nullable;
18+
import org.jspecify.annotations.Nullable;
1919

2020
import java.util.Collections;
2121

@@ -64,11 +64,9 @@ class Builder {
6464

6565
private Tags tags = Tags.empty();
6666

67-
@Nullable
68-
private String description;
67+
private @Nullable String description;
6968

70-
@Nullable
71-
private String baseUnit;
69+
private @Nullable String baseUnit;
7270

7371
private Builder(String name) {
7472
this.name = name;

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

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

18-
import io.micrometer.common.lang.Nullable;
1918
import io.micrometer.core.instrument.distribution.CountAtBucket;
2019
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
2120
import io.micrometer.core.instrument.distribution.HistogramSupport;
2221
import io.micrometer.core.instrument.distribution.ValueAtPercentile;
22+
import org.jspecify.annotations.Nullable;
2323

2424
import java.time.Duration;
2525
import java.util.Arrays;
@@ -121,11 +121,9 @@ class Builder {
121121

122122
private DistributionStatisticConfig.Builder distributionConfigBuilder = DistributionStatisticConfig.builder();
123123

124-
@Nullable
125-
private String description;
124+
private @Nullable String description;
126125

127-
@Nullable
128-
private String baseUnit;
126+
private @Nullable String baseUnit;
129127

130128
private double scale = 1.0;
131129

@@ -189,7 +187,7 @@ public Builder baseUnit(@Nullable String unit) {
189187
* should be expressed as {@code 0.95}.
190188
* @return This builder.
191189
*/
192-
public Builder publishPercentiles(@Nullable double... percentiles) {
190+
public Builder publishPercentiles(double @Nullable ... percentiles) {
193191
this.distributionConfigBuilder.percentiles(percentiles);
194192
return this;
195193
}
@@ -284,7 +282,7 @@ public Builder sla(@Nullable double... sla) {
284282
* @return This builder.
285283
* @since 1.5.0
286284
*/
287-
public Builder serviceLevelObjectives(@Nullable double... slos) {
285+
public Builder serviceLevelObjectives(double @Nullable ... slos) {
288286
this.distributionConfigBuilder.serviceLevelObjectives(slos);
289287
return this;
290288
}

0 commit comments

Comments
 (0)