diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java index f84a334724aa7..bffd54d9b832c 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java @@ -30,7 +30,6 @@ import jakarta.enterprise.context.Dependent; import jakarta.enterprise.inject.CreationException; -import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigValue; import org.eclipse.microprofile.config.inject.ConfigProperties; import org.eclipse.microprofile.config.inject.ConfigProperty; @@ -42,10 +41,8 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; import org.jboss.jandex.MethodInfo; -import org.jboss.jandex.ParameterizedType; import org.jboss.jandex.Type; import org.jboss.jandex.Type.Kind; -import org.jboss.logging.Logger; import io.quarkus.arc.Unremovable; import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem; @@ -67,7 +64,6 @@ import io.quarkus.deployment.builditem.ConfigPropertiesBuildItem; import io.quarkus.deployment.builditem.ConfigurationBuildItem; import io.quarkus.deployment.builditem.GeneratedClassBuildItem; -import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.configuration.definition.RootDefinition; import io.quarkus.deployment.recording.RecorderContext; @@ -80,14 +76,11 @@ * MicroProfile Config related build steps. */ public class ConfigBuildStep { - private static final Logger LOGGER = Logger.getLogger(ConfigBuildStep.class.getName()); - private static final DotName MP_CONFIG = DotName.createSimple(Config.class.getName()); static final DotName MP_CONFIG_PROPERTY_NAME = DotName.createSimple(ConfigProperty.class.getName()); private static final DotName MP_CONFIG_PROPERTIES_NAME = DotName.createSimple(ConfigProperties.class.getName()); private static final DotName MP_CONFIG_VALUE_NAME = DotName.createSimple(ConfigValue.class.getName()); - private static final DotName SR_CONFIG = DotName.createSimple(io.smallrye.config.SmallRyeConfig.class.getName()); private static final DotName SR_CONFIG_VALUE_NAME = DotName.createSimple(io.smallrye.config.ConfigValue.class.getName()); private static final DotName MAP_NAME = DotName.createSimple(Map.class.getName()); @@ -474,67 +467,6 @@ void validateConfigPropertiesInjectionPoints( toRegister.forEach(configProperties::produce); } - @BuildStep - void warnStaticInitInjectionPoints( - CombinedIndexBuildItem indexBuildItem, - ValidationPhaseBuildItem validationPhase, - List configClasses, - List configInjectionStaticInit, - BuildProducer runTimeConfigurationDefault) { - - // Add here annotated classes that are initialized during static init - Set declaringClassCandidates = configInjectionStaticInit.stream() - .map(ConfigInjectionStaticInitBuildItem::getDeclaringCandidate).collect(toSet()); - - Set configClassesTypes = configClasses.stream().map(ConfigClassBuildItem::getTypes).flatMap(Collection::stream) - .collect(toSet()); - - for (InjectionPointInfo injectionPoint : validationPhase.getContext().getInjectionPoints()) { - if (injectionPoint.getType().name().equals(DotNames.INSTANCE)) { - continue; - } - - Type type = Type.create(injectionPoint.getRequiredType().name(), Type.Kind.CLASS); - DotName injectionTypeName = null; - if (type.name().equals(MP_CONFIG) || type.name().equals(SR_CONFIG)) { - injectionTypeName = type.name(); - } else if (injectionPoint.getRequiredQualifier(MP_CONFIG_PROPERTY_NAME) != null) { - injectionTypeName = MP_CONFIG_PROPERTY_NAME; - } else if (configClassesTypes.contains(type)) { - injectionTypeName = type.name(); - } - - if (injectionTypeName != null) { - AnnotationTarget target = injectionPoint.getTarget(); - if (FIELD.equals(target.kind())) { - FieldInfo field = target.asField(); - ClassInfo declaringClass = field.declaringClass(); - Map> annotationsMap = declaringClass.annotationsMap(); - for (DotName declaringClassCandidate : declaringClassCandidates) { - List annotationInstances = annotationsMap.get(declaringClassCandidate); - if (annotationInstances != null && annotationInstances.size() == 1) { - AnnotationInstance annotationInstance = annotationInstances.get(0); - if (annotationInstance.target().equals(declaringClass)) { - LOGGER.warn("Directly injecting a " + - injectionTypeName + - " into a " + - declaringClassCandidate + - " may lead to unexpected results. To ensure proper results, please " + - "change the type of the field to " + - ParameterizedType.create(DotNames.INSTANCE, new Type[] { type }, null) + - ". Offending field is '" + - field.name() + - "' of class '" + - field.declaringClass() + - "'"); - } - } - } - } - } - } - } - @BuildStep @Record(RUNTIME_INIT) void registerConfigClasses( diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigInjectionStaticInitBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigInjectionStaticInitBuildItem.java index efb1919e33b02..78be1302d7c80 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigInjectionStaticInitBuildItem.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigInjectionStaticInitBuildItem.java @@ -4,6 +4,11 @@ import io.quarkus.builder.item.MultiBuildItem; +/** + * + * @deprecated This build item is not used anymore + */ +@Deprecated(forRemoval = true) public final class ConfigInjectionStaticInitBuildItem extends MultiBuildItem { private final DotName declaringCandidate; diff --git a/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java b/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java index de8247f62696b..b78d5eec48b58 100644 --- a/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java +++ b/extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java @@ -43,7 +43,6 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem; import io.quarkus.arc.deployment.BeanContainerBuildItem; -import io.quarkus.arc.deployment.ConfigInjectionStaticInitBuildItem; import io.quarkus.arc.deployment.UnremovableBeanBuildItem; import io.quarkus.arc.processor.DotNames; import io.quarkus.deployment.Capabilities; @@ -181,11 +180,6 @@ ResteasyInjectionReadyBuildItem setupResteasyInjection( return new ResteasyInjectionReadyBuildItem(injectorFactory); } - @BuildStep - ConfigInjectionStaticInitBuildItem configInjectionStaticInitProvider() { - return new ConfigInjectionStaticInitBuildItem(ResteasyDotNames.PROVIDER); - } - @BuildStep JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer reflectiveClass, CombinedIndexBuildItem indexBuildItem, diff --git a/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/config/ProviderConfigInjectionWarningsTest.java b/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/config/ProviderConfigInjectionWarningsTest.java deleted file mode 100644 index 305dc9592f2f2..0000000000000 --- a/extensions/resteasy-classic/resteasy/deployment/src/test/java/io/quarkus/resteasy/test/config/ProviderConfigInjectionWarningsTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.quarkus.resteasy.test.config; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.stream.Collectors; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.ext.ContextResolver; -import jakarta.ws.rs.ext.Provider; -import jakarta.ws.rs.ext.Providers; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.inject.ConfigProperty; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.runtime.annotations.StaticInitSafe; -import io.quarkus.test.QuarkusUnitTest; -import io.restassured.RestAssured; -import io.smallrye.config.ConfigMapping; -import io.smallrye.config.SmallRyeConfig; -import io.smallrye.config.WithDefault; - -public class ProviderConfigInjectionWarningsTest { - - @RegisterExtension - static final QuarkusUnitTest TEST = new QuarkusUnitTest() - .setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()) - .assertLogRecords(logRecords -> { - Set messages = logRecords.stream() - .map(LogRecord::getMessage) - // filter out noise coming from RESTEasy - .filter(m -> !m.contains("RESTEASY004687")) - .collect(Collectors.toSet()); - - assertEquals(4, messages.size()); - assertTrue(messages.contains( - "Directly injecting a org.eclipse.microprofile.config.Config into a jakarta.ws.rs.ext.Provider may lead to unexpected results. To ensure proper results, please change the type of the field to jakarta.enterprise.inject.Instance. Offending field is 'config' of class 'io.quarkus.resteasy.test.config.ProviderConfigInjectionWarningsTest$FooProvider'")); - assertTrue(messages.contains( - "Directly injecting a io.smallrye.config.SmallRyeConfig into a jakarta.ws.rs.ext.Provider may lead to unexpected results. To ensure proper results, please change the type of the field to jakarta.enterprise.inject.Instance. Offending field is 'smallRyeConfig' of class 'io.quarkus.resteasy.test.config.ProviderConfigInjectionWarningsTest$FooProvider'")); - assertTrue(messages.contains( - "Directly injecting a org.eclipse.microprofile.config.inject.ConfigProperty into a jakarta.ws.rs.ext.Provider may lead to unexpected results. To ensure proper results, please change the type of the field to jakarta.enterprise.inject.Instance. Offending field is 'configProperty' of class 'io.quarkus.resteasy.test.config.ProviderConfigInjectionWarningsTest$FooProvider'")); - assertTrue(messages.contains( - "Directly injecting a io.quarkus.resteasy.test.config.ProviderConfigInjectionWarningsTest$MyConfigMapping into a jakarta.ws.rs.ext.Provider may lead to unexpected results. To ensure proper results, please change the type of the field to jakarta.enterprise.inject.Instance. Offending field is 'myConfigMapping' of class 'io.quarkus.resteasy.test.config.ProviderConfigInjectionWarningsTest$FooProvider'")); - }); - - @Test - public void configWarnings() { - RestAssured.when().get("/test").then().body(Matchers.is("foo")); - } - - @Path("/test") - public static class TestResource { - @Context - private Providers providers; - - @GET - public String getFoo() { - return providers.getContextResolver(String.class, MediaType.TEXT_PLAIN_TYPE).getContext(null); - } - } - - @Provider - public static class FooProvider implements ContextResolver { - @Inject - Config config; - @Inject - Instance configInstance; - @Inject - SmallRyeConfig smallRyeConfig; - @Inject - Instance smallRyeConfigInstance; - @ConfigProperty(name = "configProperty", defaultValue = "configProperty") - String configProperty; - @ConfigProperty(name = "configProperty", defaultValue = "configProperty") - Instance stringInstance; - @Inject - MyConfigMapping myConfigMapping; - @Inject - Instance myConfigMappingInstance; - - @Override - public String getContext(Class type) { - return "foo"; - } - } - - @StaticInitSafe - @ConfigMapping(prefix = "my.mapping") - public interface MyConfigMapping { - @WithDefault("myProperty") - String myProperty(); - } -} diff --git a/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/UndertowBuildStep.java b/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/UndertowBuildStep.java index 06fd8dd5d7169..415204b0d4fc2 100644 --- a/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/UndertowBuildStep.java +++ b/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/UndertowBuildStep.java @@ -81,7 +81,6 @@ import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem; import io.quarkus.arc.deployment.BeanContainerBuildItem; -import io.quarkus.arc.deployment.ConfigInjectionStaticInitBuildItem; import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem; import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem; import io.quarkus.arc.deployment.CustomScopeBuildItem; @@ -685,11 +684,6 @@ SyntheticBeanBuildItem servletContextBean( .supplier(recorder.servletContextSupplier()).done(); } - @BuildStep - ConfigInjectionStaticInitBuildItem configInjectionStaticInitAnnotations() { - return new ConfigInjectionStaticInitBuildItem(WEB_FILTER); - } - /** * Process a single index. * diff --git a/extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/config/WebFilterConfigInjectionWarningsTest.java b/extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/config/WebFilterConfigInjectionWarningsTest.java deleted file mode 100644 index a6e2a3e04bec4..0000000000000 --- a/extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/config/WebFilterConfigInjectionWarningsTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.quarkus.undertow.test.config; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.stream.Collectors; - -import jakarta.enterprise.inject.Instance; -import jakarta.servlet.Filter; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.annotation.WebFilter; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import org.eclipse.microprofile.config.inject.ConfigProperty; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.runtime.annotations.StaticInitSafe; -import io.quarkus.test.QuarkusUnitTest; -import io.restassured.RestAssured; -import io.smallrye.config.common.MapBackedConfigSource; - -public class WebFilterConfigInjectionWarningsTest { - @RegisterExtension - static final QuarkusUnitTest TEST = new QuarkusUnitTest() - .withApplicationRoot(jar -> jar.addAsServiceProvider("org.eclipse.microprofile.config.spi.ConfigSource", - StaticConfigSource.class.getName(), RuntimeConfigSource.class.getName())) - .setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()) - .assertLogRecords(logRecords -> { - assertEquals(1, logRecords.size()); - Set messages = logRecords.stream().map(LogRecord::getMessage).collect(Collectors.toSet()); - assertTrue(messages.contains( - "Directly injecting a org.eclipse.microprofile.config.inject.ConfigProperty into a jakarta.servlet" + - ".annotation.WebFilter may lead to unexpected results. To ensure proper results, please change the " - + - "type of the field to jakarta.enterprise.inject.Instance. Offending field is " - + - "'configProperty' of class 'io.quarkus.undertow.test.config" + - ".WebFilterConfigInjectionWarningsTest$ConfigFilter'")); - }); - - @Test - public void configWarnings() { - RestAssured.when().get("/config").then().body(Matchers.is("static runtime")); - } - - @WebFilter(filterName = "ConfigFilter", servletNames = "config") - public static class ConfigFilter implements Filter { - @ConfigProperty(name = "configProperty", defaultValue = "configProperty") - String configProperty; - @ConfigProperty(name = "configProperty", defaultValue = "configProperty") - Instance configPropertyInstance; - - @Override - public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, - final FilterChain filterChain) throws IOException, ServletException { - filterChain.doFilter(servletRequest, servletResponse); - servletResponse.getWriter().write(configProperty + " " + configPropertyInstance.get()); - } - } - - @WebServlet(name = "config", urlPatterns = "/config") - public static class ConfigServlet extends HttpServlet { - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - resp.getWriter().write(""); - } - } - - @StaticInitSafe - public static class StaticConfigSource extends MapBackedConfigSource { - public StaticConfigSource() { - super("static", Map.of("configProperty", "static"), 100); - } - } - - public static class RuntimeConfigSource extends MapBackedConfigSource { - public RuntimeConfigSource() { - super("runtime", Map.of("configProperty", "runtime"), 200); - } - } -}