From 7c9416d25d01a9593289c70d8db5065151d660a8 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Fri, 25 Aug 2023 11:02:48 +0200 Subject: [PATCH 1/4] Changing Jakarta provide to `BeanProvider` as it's lazy --- .../micronaut/http/converters/HttpConverterRegistrar.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java index 176f5edc43f..f5a61bb2d05 100644 --- a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java +++ b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java @@ -15,6 +15,7 @@ */ package io.micronaut.http.converters; +import io.micronaut.context.BeanProvider; import io.micronaut.context.annotation.Prototype; import io.micronaut.context.exceptions.ConfigurationException; import io.micronaut.core.convert.MutableConversionService; @@ -22,7 +23,6 @@ import io.micronaut.core.io.Readable; import io.micronaut.core.io.ResourceLoader; import io.micronaut.core.io.ResourceResolver; -import jakarta.inject.Provider; import java.net.URL; import java.util.Optional; @@ -36,14 +36,14 @@ @Prototype public class HttpConverterRegistrar implements TypeConverterRegistrar { - private final Provider resourceResolver; + private final BeanProvider resourceResolver; /** * Default constructor. * * @param resourceResolver The resource resolver */ - protected HttpConverterRegistrar(Provider resourceResolver) { + protected HttpConverterRegistrar(BeanProvider resourceResolver) { this.resourceResolver = resourceResolver; } @@ -55,7 +55,7 @@ public void register(MutableConversionService conversionService) { (object, targetType, context) -> { String pathStr = object.toString(); Optional supportingLoader = resourceResolver.get().getSupportingLoader(pathStr); - if (!supportingLoader.isPresent()) { + if (supportingLoader.isEmpty()) { context.reject(pathStr, new ConfigurationException( "No supported resource loader for path [" + pathStr + "]. Prefix the path with a supported prefix such as 'classpath:' or 'file:'" )); From ea80216cceaee2e4a8b95fef8d26708d78f40c7a Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Fri, 25 Aug 2023 11:49:00 +0200 Subject: [PATCH 2/4] Address CR --- .../http/converters/HttpConverterRegistrar.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java index f5a61bb2d05..8fe61f178a7 100644 --- a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java +++ b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java @@ -23,6 +23,8 @@ import io.micronaut.core.io.Readable; import io.micronaut.core.io.ResourceLoader; import io.micronaut.core.io.ResourceResolver; +import jakarta.inject.Inject; +import jakarta.inject.Provider; import java.net.URL; import java.util.Optional; @@ -43,9 +45,24 @@ public class HttpConverterRegistrar implements TypeConverterRegistrar { * * @param resourceResolver The resource resolver */ + @Inject protected HttpConverterRegistrar(BeanProvider resourceResolver) { this.resourceResolver = resourceResolver; } + /** + * The constructor. + * + * @param resourceResolver The resource resolver + */ + @Deprecated + protected HttpConverterRegistrar(Provider resourceResolver) { + this.resourceResolver = new BeanProvider() { + @Override + public ResourceResolver get() { + return resourceResolver.get(); + } + }; + } @Override public void register(MutableConversionService conversionService) { From f39b812aa69e66b88eb279800f45bd54aa578ea1 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Sun, 27 Aug 2023 10:11:54 +0200 Subject: [PATCH 3/4] Checkstyle --- .../io/micronaut/http/converters/HttpConverterRegistrar.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java index 8fe61f178a7..09128033a02 100644 --- a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java +++ b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java @@ -53,8 +53,9 @@ protected HttpConverterRegistrar(BeanProvider resourceResolver * The constructor. * * @param resourceResolver The resource resolver + * @deprecated Replaced by {@link #HttpConverterRegistrar(BeanProvider)}. */ - @Deprecated + @Deprecated(forRemoval = true) protected HttpConverterRegistrar(Provider resourceResolver) { this.resourceResolver = new BeanProvider() { @Override From 9364e3498c8ab4e38817fc64ab4c2508094fa88d Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Mon, 28 Aug 2023 07:59:30 +0200 Subject: [PATCH 4/4] Checkstyle --- .../io/micronaut/http/converters/HttpConverterRegistrar.java | 1 + 1 file changed, 1 insertion(+) diff --git a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java index 09128033a02..082f7d55281 100644 --- a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java +++ b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java @@ -49,6 +49,7 @@ public class HttpConverterRegistrar implements TypeConverterRegistrar { protected HttpConverterRegistrar(BeanProvider resourceResolver) { this.resourceResolver = resourceResolver; } + /** * The constructor. *