From 1a2c53991d46306519b82839283c958041fb4804 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Mon, 2 Dec 2024 15:33:01 -0800 Subject: [PATCH] Eliminate unnecessary null check --- .../io/micrometer/core/instrument/MeterRegistry.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java index 81859669b..b41e3b80d 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java @@ -616,22 +616,18 @@ private Meter getOrCreateMeter(@Nullable DistributionStatisticConfig config, BiFunction builder, Id originalId, Id mappedId, Function noopBuilder) { Meter m = meterMap.get(mappedId); + checkAndWarnAboutGaugeDoubleRegistration(m); - if (m != null) { - checkAndWarnAboutGaugeDoubleRegistration(m); - } - else { + if (m == null) { if (isClosed()) { return noopBuilder.apply(mappedId); } synchronized (meterMapLock) { m = meterMap.get(mappedId); + checkAndWarnAboutGaugeDoubleRegistration(m); - if (m != null) { - checkAndWarnAboutGaugeDoubleRegistration(m); - } - else { + if (m == null) { if (!accept(mappedId)) { return noopBuilder.apply(mappedId); }