From c95d2ee95aaaed2f71f315f20775bbaefcb88570 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 6 Sep 2023 10:42:25 +0200 Subject: [PATCH] Correct how maps/sets are initialized with a correct size --- aop/src/main/java/io/micronaut/aop/InvocationContext.java | 4 ++-- .../inject/processing/DeclaredBeanElementCreator.java | 4 ++-- .../inject/writer/AbstractBeanDefinitionBuilder.java | 2 +- .../inject/writer/DefaultOriginatingElements.java | 3 ++- .../java/io/micronaut/core/reflect/InstantiationUtils.java | 3 ++- .../main/java/io/micronaut/core/type/DefaultArgument.java | 3 +-- core/src/main/java/io/micronaut/core/type/ReturnType.java | 7 ++++--- .../cloud/ComputeInstanceMetadataResolverUtils.java | 6 +++--- .../function/client/DefaultFunctionDiscoveryClient.java | 4 ++-- .../micronaut/http/client/DefaultLoadBalancerResolver.java | 3 +-- .../java/io/micronaut/http/netty/NettyHttpParameters.java | 3 ++- .../netty/websocket/AbstractNettyWebSocketHandler.java | 4 ++-- .../main/java/io/micronaut/http/uri/UriMatchTemplate.java | 3 ++- .../io/micronaut/ast/groovy/utils/AstGenericUtils.groovy | 5 +++-- .../io/micronaut/annotation/processing/GenericUtils.java | 7 ++++--- .../context/env/PropertySourcePropertyResolver.java | 2 +- .../inject/annotation/MutableAnnotationMetadata.java | 4 ++-- .../io/micronaut/json/bind/JsonBeanPropertyBinder.java | 2 +- .../health/aggregator/DefaultHealthAggregator.java | 4 ++-- 19 files changed, 39 insertions(+), 34 deletions(-) diff --git a/aop/src/main/java/io/micronaut/aop/InvocationContext.java b/aop/src/main/java/io/micronaut/aop/InvocationContext.java index f10848acbe4..644353f8f2b 100644 --- a/aop/src/main/java/io/micronaut/aop/InvocationContext.java +++ b/aop/src/main/java/io/micronaut/aop/InvocationContext.java @@ -23,8 +23,8 @@ import io.micronaut.core.type.ArgumentValue; import io.micronaut.core.type.Executable; import io.micronaut.core.type.MutableArgumentValue; +import io.micronaut.core.util.CollectionUtils; -import java.util.LinkedHashMap; import java.util.Map; /** @@ -117,7 +117,7 @@ default InvocationContext setAttribute(@NonNull CharSequence name, Object default @NonNull Map getParameterValueMap() { Argument[] arguments = getArguments(); Object[] parameterValues = getParameterValues(); - Map valueMap = new LinkedHashMap<>(arguments.length); + Map valueMap = CollectionUtils.newLinkedHashMap(arguments.length); for (int i = 0; i < parameterValues.length; i++) { Object parameterValue = parameterValues[i]; Argument arg = arguments[i]; diff --git a/core-processor/src/main/java/io/micronaut/inject/processing/DeclaredBeanElementCreator.java b/core-processor/src/main/java/io/micronaut/inject/processing/DeclaredBeanElementCreator.java index 8fef82f6e24..b8d93acb5f0 100644 --- a/core-processor/src/main/java/io/micronaut/inject/processing/DeclaredBeanElementCreator.java +++ b/core-processor/src/main/java/io/micronaut/inject/processing/DeclaredBeanElementCreator.java @@ -30,6 +30,7 @@ import io.micronaut.core.annotation.NonNull; import io.micronaut.core.annotation.Nullable; import io.micronaut.core.annotation.Vetoed; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.core.util.StringUtils; import io.micronaut.inject.annotation.AnnotationMetadataHierarchy; import io.micronaut.inject.ast.ClassElement; @@ -49,7 +50,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -617,7 +617,7 @@ private void visitAdaptedMethod(MethodElement sourceMethod) { } Map typeVariables = interfaceToAdapt.getTypeArguments(); - Map genericTypes = new LinkedHashMap<>(paramLen); + Map genericTypes = CollectionUtils.newLinkedHashMap(paramLen); for (int i = 0; i < paramLen; i++) { ParameterElement targetParam = targetParams[i]; ParameterElement sourceParam = sourceParams[i]; diff --git a/core-processor/src/main/java/io/micronaut/inject/writer/AbstractBeanDefinitionBuilder.java b/core-processor/src/main/java/io/micronaut/inject/writer/AbstractBeanDefinitionBuilder.java index 4b022abd0ce..d46a568c5b2 100644 --- a/core-processor/src/main/java/io/micronaut/inject/writer/AbstractBeanDefinitionBuilder.java +++ b/core-processor/src/main/java/io/micronaut/inject/writer/AbstractBeanDefinitionBuilder.java @@ -358,7 +358,7 @@ public BeanElementBuilder typeArgumentsForType(ClassElement type, @NonNull Class private Map resolveTypeArguments(Map typeArguments, ClassElement... types) { Map resolvedTypes = null; if (typeArguments.size() == types.length) { - resolvedTypes = new LinkedHashMap<>(typeArguments.size()); + resolvedTypes = CollectionUtils.newLinkedHashMap(typeArguments.size()); final Iterator i = typeArguments.keySet().iterator(); for (ClassElement type : types) { final String variable = i.next(); diff --git a/core-processor/src/main/java/io/micronaut/inject/writer/DefaultOriginatingElements.java b/core-processor/src/main/java/io/micronaut/inject/writer/DefaultOriginatingElements.java index 0be9959f1ea..42fe7b6a20f 100644 --- a/core-processor/src/main/java/io/micronaut/inject/writer/DefaultOriginatingElements.java +++ b/core-processor/src/main/java/io/micronaut/inject/writer/DefaultOriginatingElements.java @@ -17,6 +17,7 @@ import io.micronaut.core.annotation.Internal; import io.micronaut.core.annotation.NonNull; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.inject.ast.Element; import java.util.*; @@ -36,7 +37,7 @@ final class DefaultOriginatingElements implements OriginatingElements { * @param originatingElements The elements */ DefaultOriginatingElements(Element... originatingElements) { - this.originatingElements = new LinkedHashMap<>(originatingElements != null ? originatingElements.length : 5); + this.originatingElements = CollectionUtils.newLinkedHashMap(originatingElements != null ? originatingElements.length : 5); if (originatingElements != null) { for (Element originatingElement : originatingElements) { if (originatingElement != null) { diff --git a/core/src/main/java/io/micronaut/core/reflect/InstantiationUtils.java b/core/src/main/java/io/micronaut/core/reflect/InstantiationUtils.java index 381cb46eb9e..3444b67c1fb 100644 --- a/core/src/main/java/io/micronaut/core/reflect/InstantiationUtils.java +++ b/core/src/main/java/io/micronaut/core/reflect/InstantiationUtils.java @@ -24,6 +24,7 @@ import io.micronaut.core.reflect.exception.InstantiationException; import io.micronaut.core.type.Argument; import io.micronaut.core.util.ArgumentUtils; +import io.micronaut.core.util.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +94,7 @@ public static Optional tryInstantiate(String name, ClassLoader classLoader) { try { if (constructorArguments.length > 0) { - Map bindMap = new LinkedHashMap(propertiesMap.size()); + Map bindMap = CollectionUtils.newLinkedHashMap(propertiesMap.size()); Set> entries = propertiesMap.entrySet(); for (Map.Entry entry : entries) { Object key = entry.getKey(); diff --git a/core/src/main/java/io/micronaut/core/type/DefaultArgument.java b/core/src/main/java/io/micronaut/core/type/DefaultArgument.java index f7524446e82..7e8e1a806f6 100644 --- a/core/src/main/java/io/micronaut/core/type/DefaultArgument.java +++ b/core/src/main/java/io/micronaut/core/type/DefaultArgument.java @@ -31,7 +31,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Deque; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -295,7 +294,7 @@ public int hashCode() { private static Map> initializeTypeParameters(Argument[] genericTypes) { Map> typeParameters; if (genericTypes != null && genericTypes.length > 0) { - typeParameters = new LinkedHashMap<>(genericTypes.length); + typeParameters = CollectionUtils.newLinkedHashMap(genericTypes.length); for (Argument genericType : genericTypes) { typeParameters.put(genericType.getName(), genericType); } diff --git a/core/src/main/java/io/micronaut/core/type/ReturnType.java b/core/src/main/java/io/micronaut/core/type/ReturnType.java index a4d44345b8b..260ebb8027a 100644 --- a/core/src/main/java/io/micronaut/core/type/ReturnType.java +++ b/core/src/main/java/io/micronaut/core/type/ReturnType.java @@ -15,10 +15,11 @@ */ package io.micronaut.core.type; -import io.micronaut.core.annotation.NonNull; import io.micronaut.core.annotation.AnnotationMetadataProvider; +import io.micronaut.core.annotation.NonNull; +import io.micronaut.core.util.CollectionUtils; + import java.util.Collection; -import java.util.LinkedHashMap; import java.util.Map; /** @@ -73,7 +74,7 @@ default boolean isSingleResult() { * @return A {@link ReturnType} */ static ReturnType of(Class type, Argument... typeArguments) { - Map> argumentMap = new LinkedHashMap<>(typeArguments.length); + Map> argumentMap = CollectionUtils.newLinkedHashMap(typeArguments.length); for (Argument argument : typeArguments) { argumentMap.put(argument.getName(), argument); } diff --git a/discovery-core/src/main/java/io/micronaut/discovery/cloud/ComputeInstanceMetadataResolverUtils.java b/discovery-core/src/main/java/io/micronaut/discovery/cloud/ComputeInstanceMetadataResolverUtils.java index 6f8d76a7616..dbcfc975776 100644 --- a/discovery-core/src/main/java/io/micronaut/discovery/cloud/ComputeInstanceMetadataResolverUtils.java +++ b/discovery-core/src/main/java/io/micronaut/discovery/cloud/ComputeInstanceMetadataResolverUtils.java @@ -21,6 +21,7 @@ import io.micronaut.core.annotation.Experimental; import io.micronaut.core.annotation.Internal; import io.micronaut.core.type.Argument; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.http.HttpMethod; import io.micronaut.jackson.core.tree.JsonNodeTreeCodec; import io.micronaut.json.JsonMapper; @@ -31,7 +32,6 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -125,7 +125,7 @@ private static InputStream openMetadataUrl(URL url, int connectionTimeoutMs, int @Experimental public static void populateMetadata(AbstractComputeInstanceMetadata instanceMetadata, JsonNode metadata) { if (metadata != null) { - Map finalMetadata = new HashMap<>(metadata.size()); + Map finalMetadata = CollectionUtils.newHashMap(metadata.size()); for (Map.Entry entry : metadata.entries()) { JsonNode value = entry.getValue(); if (value.isString()) { @@ -155,7 +155,7 @@ public static Optional stringValue(com.fasterxml.jackson.databind.JsonNo */ public static void populateMetadata(AbstractComputeInstanceMetadata instanceMetadata, Map metadata) { if (metadata != null) { - Map finalMetadata = new HashMap<>(metadata.size()); + Map finalMetadata = CollectionUtils.newHashMap(metadata.size()); for (Map.Entry entry : metadata.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); diff --git a/function-client/src/main/java/io/micronaut/function/client/DefaultFunctionDiscoveryClient.java b/function-client/src/main/java/io/micronaut/function/client/DefaultFunctionDiscoveryClient.java index 4dc80ceb1bc..046246068d9 100644 --- a/function-client/src/main/java/io/micronaut/function/client/DefaultFunctionDiscoveryClient.java +++ b/function-client/src/main/java/io/micronaut/function/client/DefaultFunctionDiscoveryClient.java @@ -16,6 +16,7 @@ package io.micronaut.function.client; import io.micronaut.core.async.publisher.Publishers; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.discovery.DiscoveryClient; import io.micronaut.discovery.ServiceInstance; import io.micronaut.function.LocalFunctionRegistry; @@ -27,7 +28,6 @@ import java.net.URI; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -52,7 +52,7 @@ public class DefaultFunctionDiscoveryClient implements FunctionDiscoveryClient { */ public DefaultFunctionDiscoveryClient(DiscoveryClient discoveryClient, FunctionDefinitionProvider[] providers, FunctionDefinition... definitions) { this.discoveryClient = discoveryClient; - this.functionDefinitionMap = new HashMap<>(definitions.length); + this.functionDefinitionMap = CollectionUtils.newHashMap(definitions.length); for (FunctionDefinition definition : definitions) { functionDefinitionMap.put(definition.getName(), definition); } diff --git a/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java b/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java index c5a0f03a274..55f64e3c32e 100644 --- a/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java +++ b/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java @@ -32,7 +32,6 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -79,7 +78,7 @@ public DefaultLoadBalancerResolver( List serviceInstanceLists) { this.beanContext = beanContext; if (CollectionUtils.isNotEmpty(serviceInstanceLists)) { - this.serviceInstanceLists = new HashMap<>(serviceInstanceLists.size()); + this.serviceInstanceLists = CollectionUtils.newHashMap(serviceInstanceLists.size()); for (ServiceInstanceList provider : serviceInstanceLists) { this.serviceInstanceLists.put(provider.getID(), provider); } diff --git a/http-netty/src/main/java/io/micronaut/http/netty/NettyHttpParameters.java b/http-netty/src/main/java/io/micronaut/http/netty/NettyHttpParameters.java index 07a811e2062..013950a0a86 100644 --- a/http-netty/src/main/java/io/micronaut/http/netty/NettyHttpParameters.java +++ b/http-netty/src/main/java/io/micronaut/http/netty/NettyHttpParameters.java @@ -20,6 +20,7 @@ import io.micronaut.core.convert.ArgumentConversionContext; import io.micronaut.core.convert.ConversionService; import io.micronaut.core.convert.value.ConvertibleMultiValuesMap; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.http.MutableHttpParameters; import java.util.ArrayList; @@ -54,7 +55,7 @@ public class NettyHttpParameters implements MutableHttpParameters { public NettyHttpParameters(Map> parameters, ConversionService conversionService, @Nullable BiConsumer> onChange) { - this.valuesMap = new LinkedHashMap<>(parameters.size()); + this.valuesMap = CollectionUtils.newLinkedHashMap(parameters.size()); this.values = new ConvertibleMultiValuesMap<>(valuesMap, conversionService); this.onChange = onChange; for (Map.Entry> entry : parameters.entrySet()) { diff --git a/http-netty/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.java b/http-netty/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.java index c543c151ad8..2e22928e361 100644 --- a/http-netty/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.java +++ b/http-netty/src/main/java/io/micronaut/http/netty/websocket/AbstractNettyWebSocketHandler.java @@ -25,6 +25,7 @@ import io.micronaut.core.bind.exceptions.UnsatisfiedArgumentException; import io.micronaut.core.convert.ConversionService; import io.micronaut.core.type.Argument; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.http.HttpRequest; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.Consumes; @@ -61,7 +62,6 @@ import java.io.IOException; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -559,7 +559,7 @@ private BoundExecutable bindMethod(HttpRequest request, ArgumentBinderRegistr } private Map, Object> prepareBoundVariables(ExecutableMethod executable, List parameters) { - Map, Object> preBound = new HashMap<>(executable.getArguments().length); + Map, Object> preBound = CollectionUtils.newHashMap(executable.getArguments().length); for (Argument argument : executable.getArguments()) { Class type = argument.getType(); for (Object object : parameters) { diff --git a/http/src/main/java/io/micronaut/http/uri/UriMatchTemplate.java b/http/src/main/java/io/micronaut/http/uri/UriMatchTemplate.java index ab4491db89c..7b8bb15d451 100644 --- a/http/src/main/java/io/micronaut/http/uri/UriMatchTemplate.java +++ b/http/src/main/java/io/micronaut/http/uri/UriMatchTemplate.java @@ -17,6 +17,7 @@ import io.micronaut.core.annotation.NonNull; import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.core.util.ObjectUtils; import java.util.ArrayList; @@ -200,7 +201,7 @@ public UriMatchInfo tryMatch(@NonNull String uri) { return new DefaultUriMatchInfo(uri, Collections.emptyMap(), variables); } else { int count = matcher.groupCount(); - Map variableMap = new LinkedHashMap<>(count); + Map variableMap = CollectionUtils.newLinkedHashMap(count); for (int j = 0; j < variables.size(); j++) { int index = (j * 2) + 2; if (index > count) { diff --git a/inject-groovy/src/main/groovy/io/micronaut/ast/groovy/utils/AstGenericUtils.groovy b/inject-groovy/src/main/groovy/io/micronaut/ast/groovy/utils/AstGenericUtils.groovy index 26f342e8da6..d916a3b5dc3 100644 --- a/inject-groovy/src/main/groovy/io/micronaut/ast/groovy/utils/AstGenericUtils.groovy +++ b/inject-groovy/src/main/groovy/io/micronaut/ast/groovy/utils/AstGenericUtils.groovy @@ -17,6 +17,7 @@ package io.micronaut.ast.groovy.utils import groovy.transform.CompileStatic import io.micronaut.core.util.ArrayUtils +import io.micronaut.core.util.CollectionUtils import io.micronaut.inject.visitor.VisitorContext import org.codehaus.groovy.ast.ClassHelper import org.codehaus.groovy.ast.ClassNode @@ -245,10 +246,10 @@ class AstGenericUtils { populateTypeArguments(classNode, typeArguments) - Map> elements = new LinkedHashMap<>(typeArguments.size()) + Map> elements = CollectionUtils.newLinkedHashMap(typeArguments.size()) for (Map.Entry> entry : typeArguments.entrySet()) { Map value = entry.getValue() - HashMap submap = new LinkedHashMap<>(value.size()) + HashMap submap = CollectionUtils.newLinkedHashMap(value.size()) for (Map.Entry genericEntry : value.entrySet()) { def v = genericEntry.getValue() ClassNode te = null diff --git a/inject-java/src/main/java/io/micronaut/annotation/processing/GenericUtils.java b/inject-java/src/main/java/io/micronaut/annotation/processing/GenericUtils.java index bae11c61695..a363a5a7da3 100644 --- a/inject-java/src/main/java/io/micronaut/annotation/processing/GenericUtils.java +++ b/inject-java/src/main/java/io/micronaut/annotation/processing/GenericUtils.java @@ -228,19 +228,20 @@ protected TypeMirror resolveTypeReference(TypeMirror mirror, Map resolveBoundTypes(DeclaredType type) { - Map boundTypes = new LinkedHashMap<>(2); TypeElement element = (TypeElement) type.asElement(); List typeParameters = element.getTypeParameters(); List typeArguments = type.getTypeArguments(); if (typeArguments.size() == typeParameters.size()) { + Map boundTypes = CollectionUtils.newLinkedHashMap(typeParameters.size()); Iterator i = typeArguments.iterator(); for (TypeParameterElement typeParameter : typeParameters) { boundTypes.put(typeParameter.toString(), resolveTypeReference(i.next(), boundTypes)); } + return boundTypes; } - return boundTypes; + return Collections.emptyMap(); } private void resolveGenericTypeParameter(Map resolvedParameters, String parameterName, TypeMirror mirror, Map boundTypes) { @@ -297,7 +298,7 @@ private void populateTypeArguments(TypeElement typeElement, Map typeParameters = current.getTypeParameters(); - Map types = new LinkedHashMap<>(typeParameters.size()); + Map types = CollectionUtils.newLinkedHashMap(typeParameters.size()); if (typeParameters.size() == superArguments.size()) { Iterator i = superArguments.iterator(); for (TypeParameterElement typeParameter : typeParameters) { diff --git a/inject/src/main/java/io/micronaut/context/env/PropertySourcePropertyResolver.java b/inject/src/main/java/io/micronaut/context/env/PropertySourcePropertyResolver.java index ef38fc05cdf..60d32870e5e 100644 --- a/inject/src/main/java/io/micronaut/context/env/PropertySourcePropertyResolver.java +++ b/inject/src/main/java/io/micronaut/context/env/PropertySourcePropertyResolver.java @@ -797,7 +797,7 @@ private Object resolvePlaceHoldersIfNecessary(Object value) { if (o instanceof CharSequence) { i.set(resolvePlaceHoldersIfNecessary(o)); } else if (o instanceof Map submap) { - Map newMap = new LinkedHashMap<>(submap.size()); + Map newMap = CollectionUtils.newLinkedHashMap(submap.size()); for (Map.Entry entry : submap.entrySet()) { final Object k = entry.getKey(); final Object v = entry.getValue(); diff --git a/inject/src/main/java/io/micronaut/inject/annotation/MutableAnnotationMetadata.java b/inject/src/main/java/io/micronaut/inject/annotation/MutableAnnotationMetadata.java index 788221219e1..2ffbe4167a3 100644 --- a/inject/src/main/java/io/micronaut/inject/annotation/MutableAnnotationMetadata.java +++ b/inject/src/main/java/io/micronaut/inject/annotation/MutableAnnotationMetadata.java @@ -605,9 +605,9 @@ private void putValues(String annotation, Map values, Map< } } else { if (!hasValues) { - existing = existing == null ? new LinkedHashMap<>(3) : existing; + existing = existing == null ? CollectionUtils.newLinkedHashMap(3) : existing; } else { - existing = new LinkedHashMap<>(values.size()); + existing = CollectionUtils.newLinkedHashMap(values.size()); existing.putAll(values); } currentAnnotationValues.put(annotation, existing); diff --git a/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java b/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java index 82ec3eb3340..4dd4120beb4 100644 --- a/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java +++ b/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java @@ -291,7 +291,7 @@ private static final class ObjectBuilder implements ValueBuilder { @Override public JsonNode build() { - Map built = new LinkedHashMap<>(values.size()); + Map built = CollectionUtils.newLinkedHashMap(values.size()); for (Map.Entry entry : values.entrySet()) { built.put(entry.getKey(), entry.getValue().build()); } diff --git a/management/src/main/java/io/micronaut/management/health/aggregator/DefaultHealthAggregator.java b/management/src/main/java/io/micronaut/management/health/aggregator/DefaultHealthAggregator.java index f4c768812e8..0e23952dac2 100644 --- a/management/src/main/java/io/micronaut/management/health/aggregator/DefaultHealthAggregator.java +++ b/management/src/main/java/io/micronaut/management/health/aggregator/DefaultHealthAggregator.java @@ -17,6 +17,7 @@ import io.micronaut.context.annotation.Requires; import io.micronaut.context.env.Environment; +import io.micronaut.core.util.CollectionUtils; import io.micronaut.health.HealthStatus; import io.micronaut.management.endpoint.health.HealthEndpoint; import io.micronaut.management.endpoint.health.HealthLevelOfDetail; @@ -29,7 +30,6 @@ import reactor.core.publisher.Mono; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -112,7 +112,7 @@ protected Flux aggregateResults(HealthIndicator[] indicators) { * @return The aggregated details for the results */ protected Object aggregateDetails(List results) { - Map details = new HashMap<>(results.size()); + Map details = CollectionUtils.newHashMap(results.size()); results.forEach(r -> details.put(r.getName(), buildResult(r.getStatus(), r.getDetails(), HealthLevelOfDetail.STATUS_DESCRIPTION_DETAILS))); return details; }