diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ApiLookupProblemDetectedTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerLookupProblemDetectedTest.java similarity index 92% rename from extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ApiLookupProblemDetectedTest.java rename to extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerLookupProblemDetectedTest.java index 1506823c865ef..7eb1d41361030 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ApiLookupProblemDetectedTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerLookupProblemDetectedTest.java @@ -17,7 +17,7 @@ import io.quarkus.arc.impl.ArcContainerImpl; import io.quarkus.test.QuarkusUnitTest; -public class ApiLookupProblemDetectedTest { +public class ArcContainerLookupProblemDetectedTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() @@ -31,10 +31,10 @@ public class ApiLookupProblemDetectedTest { Formatter fmt = new PatternFormatter("%m"); String message = fmt.format(warning); assertTrue(message.contains( - "Stack frame: io.quarkus.arc.test.unused.ApiLookupProblemDetectedTest.testWarning"), + "Stack frame: io.quarkus.arc.test.unused.ArcContainerLookupProblemDetectedTest.testWarning"), message); assertTrue(message.contains( - "Required type: class io.quarkus.arc.test.unused.ApiLookupProblemDetectedTest$Alpha"), + "Required type: class io.quarkus.arc.test.unused.ArcContainerLookupProblemDetectedTest$Alpha"), message); }); diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerSupplierLookupProblemDetectedTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerSupplierLookupProblemDetectedTest.java new file mode 100644 index 0000000000000..0a03a33d3279e --- /dev/null +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcContainerSupplierLookupProblemDetectedTest.java @@ -0,0 +1,57 @@ +package io.quarkus.arc.test.unused; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.jboss.logmanager.formatters.PatternFormatter; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.Arc; +import io.quarkus.arc.impl.ArcContainerImpl; +import io.quarkus.test.QuarkusUnitTest; + +public class ArcContainerSupplierLookupProblemDetectedTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot(root -> root + .addClasses(Alpha.class)) + .setLogRecordPredicate(log -> ArcContainerImpl.class.getPackage().getName().equals(log.getLoggerName())) + .assertLogRecords(records -> { + LogRecord warning = records.stream() + .filter(l -> l.getMessage().contains("programmatic lookup problem detected")).findAny().orElse(null); + assertNotNull(warning); + Formatter fmt = new PatternFormatter("%m"); + String message = fmt.format(warning); + assertTrue(message.contains( + "Stack frame: io.quarkus.arc.test.unused.ArcContainerSupplierLookupProblemDetectedTest.testWarning"), + message); + assertTrue(message.contains( + "Required type: class io.quarkus.arc.test.unused.ArcContainerSupplierLookupProblemDetectedTest$Alpha"), + message); + }); + + @Test + public void testWarning() { + // Note that the warning is only displayed once, subsequent calls use a cached result + assertNull(Arc.container().beanInstanceSupplier(Alpha.class)); + } + + // unused bean, will be removed + @ApplicationScoped + static class Alpha { + + public String ping() { + return "ok"; + } + + } + +} diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcLookupProblemDetectedTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/CDIProviderLookupProblemDetectedTest.java similarity index 93% rename from extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcLookupProblemDetectedTest.java rename to extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/CDIProviderLookupProblemDetectedTest.java index 664b4eeac7ece..6c83c69748da6 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/ArcLookupProblemDetectedTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/unused/CDIProviderLookupProblemDetectedTest.java @@ -18,7 +18,7 @@ import io.quarkus.arc.impl.ArcContainerImpl; import io.quarkus.test.QuarkusUnitTest; -public class ArcLookupProblemDetectedTest { +public class CDIProviderLookupProblemDetectedTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() @@ -32,10 +32,10 @@ public class ArcLookupProblemDetectedTest { Formatter fmt = new PatternFormatter("%m"); String message = fmt.format(warning); assertTrue(message.contains( - "Stack frame: io.quarkus.arc.test.unused.ArcLookupProblemDetectedTest"), + "Stack frame: io.quarkus.arc.test.unused.CDIProviderLookupProblemDetectedTest"), message); assertTrue(message.contains( - "Required type: class io.quarkus.arc.test.unused.ArcLookupProblemDetectedTest$Alpha"), + "Required type: class io.quarkus.arc.test.unused.CDIProviderLookupProblemDetectedTest$Alpha"), message); }); diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java index cc12467b83c15..12f6a9ad0a65b 100644 --- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java +++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java @@ -304,7 +304,11 @@ private Supplier> createInstanceSupplier(boolean resolveAm if (qualifiers == null || qualifiers.length == 0) { qualifiers = new Annotation[] { Default.Literal.INSTANCE }; } - Set> resolvedBeans = resolved.getValue(new Resolvable(type, qualifiers)); + Resolvable resolvable = new Resolvable(type, qualifiers); + Set> resolvedBeans = resolved.getValue(resolvable); + if (resolvedBeans.isEmpty()) { + scanRemovedBeans(resolvable); + } Set> filteredBean = resolvedBeans; if (resolvedBeans.size() > 1) { if (resolveAmbiguities) {