diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java index b4c9567565..2994f282b4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java @@ -223,7 +223,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration { @Autowired private List handlerAdapters; - private Map> converterCache = new ConcurrentHashMap>(); + private final Map> converterCache = new ConcurrentHashMap>(); @Override public boolean supports(MethodParameter returnType, @@ -278,8 +278,10 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration { private HttpMessageConverter findConverter( Class> selectedConverterType, MediaType mediaType) { - if (this.converterCache.containsKey(mediaType)) { - return (HttpMessageConverter) this.converterCache.get(mediaType); + HttpMessageConverter cached = (HttpMessageConverter) this.converterCache + .get(mediaType); + if (cached != null) { + return cached; } for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) { for (HttpMessageConverter converter : handlerAdapter diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java index 36d11fd260..f976d65f62 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/AbstractJmxCacheStatisticsProvider.java @@ -50,7 +50,7 @@ public abstract class AbstractJmxCacheStatisticsProvider private MBeanServer mBeanServer; - private Map caches = new ConcurrentHashMap(); + private final Map caches = new ConcurrentHashMap(); @Override public CacheStatistics getCacheStatistics(CacheManager cacheManager, C cache) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java index f96afa3695..602764a634 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeService.java @@ -48,8 +48,9 @@ public class BufferGaugeService implements GaugeService { } private String wrap(String metricName) { - if (this.names.containsKey(metricName)) { - return this.names.get(metricName); + String cached = this.names.get(metricName); + if (cached != null) { + return cached; } if (metricName.startsWith("gauge") || metricName.startsWith("histogram") || metricName.startsWith("timer")) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java index 8c9aad6ed9..b2da82e6ce 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jmx/JmxMetricWriter.java @@ -109,9 +109,13 @@ public class JmxMetricWriter implements MetricWriter { } private MetricValue getValue(String name) { - if (!this.values.containsKey(name)) { - this.values.putIfAbsent(name, new MetricValue()); - MetricValue value = this.values.get(name); + MetricValue value = this.values.get(name); + if (value == null) { + value = new MetricValue(); + MetricValue oldValue = this.values.putIfAbsent(name, value); + if (oldValue != null) { + value = oldValue; + } try { this.exporter.registerManagedResource(value, getName(name, value)); } @@ -119,7 +123,7 @@ public class JmxMetricWriter implements MetricWriter { // Could not register mbean, maybe just a race condition } } - return this.values.get(name); + return value; } private ObjectName getName(String name, MetricValue value) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java index 19105c53e4..0c37cdb524 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java @@ -59,13 +59,7 @@ public class SimpleInMemoryRepository { } public void set(String name, T value) { - T current = this.values.get(name); - if (current != null) { - this.values.replace(name, current, value); - } - else { - this.values.putIfAbsent(name, value); - } + this.values.put(name, value); } public long count() { @@ -77,10 +71,7 @@ public class SimpleInMemoryRepository { } public T findOne(String name) { - if (this.values.containsKey(name)) { - return this.values.get(name); - } - return null; + return this.values.get(name); } public Iterable findAll() { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeService.java index 01964d8425..c230bacb48 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeService.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeService.java @@ -46,8 +46,9 @@ public class DefaultGaugeService implements GaugeService { } private String wrap(String metricName) { - if (this.names.containsKey(metricName)) { - return this.names.get(metricName); + String cached = this.names.get(metricName); + if (cached != null) { + return cached; } if (metricName.startsWith("gauge") || metricName.startsWith("histogram") || metricName.startsWith("timer")) {