diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanInfo.java index 6d67a7b13e822..8a8e131ed07b9 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanInfo.java @@ -417,7 +417,7 @@ boolean isSubclassRequired() { * @return {@code true} if the bean requires some customized destroy logic */ public boolean hasDestroyLogic() { - if (isInterceptor() || isDecorator()) { + if (isInterceptor()) { return false; } if (disposer != null || destroyerConsumer != null) { diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DecoratorGenerator.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DecoratorGenerator.java index 2b3183d63d645..6b465ba11a4ec 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DecoratorGenerator.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DecoratorGenerator.java @@ -125,6 +125,10 @@ Collection generate(DecoratorInfo decorator) { implementCreate(classOutput, decoratorCreator, decorator, providerType, baseName, injectionPointToProviderField, Collections.emptyMap(), Collections.emptyMap(), targetPackage, isApplicationClass); + if (decorator.hasDestroyLogic()) { + implementDestroy(decorator, decoratorCreator, providerType, Collections.emptyMap(), isApplicationClass, baseName, + targetPackage); + } implementGet(decorator, decoratorCreator, providerType, baseName); implementGetTypes(decoratorCreator, beanTypes.getFieldDescriptor()); implementGetBeanClass(decorator, decoratorCreator); diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/decorators/SimpleDecoratorTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/decorators/SimpleDecoratorTest.java index 47d02b42821cc..16527b2f270c5 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/decorators/SimpleDecoratorTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/decorators/SimpleDecoratorTest.java @@ -1,7 +1,12 @@ package io.quarkus.arc.test.decorators; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.concurrent.atomic.AtomicBoolean; + +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import jakarta.annotation.Priority; import jakarta.decorator.Decorator; import jakarta.decorator.Delegate; @@ -13,6 +18,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.arc.Arc; +import io.quarkus.arc.InstanceHandle; import io.quarkus.arc.test.ArcTestContainer; public class SimpleDecoratorTest { @@ -23,9 +29,13 @@ public class SimpleDecoratorTest { @Test public void testDecoration() { - ToUpperCaseConverter converter = Arc.container().instance(ToUpperCaseConverter.class).get(); + InstanceHandle handle = Arc.container().instance(ToUpperCaseConverter.class); + ToUpperCaseConverter converter = handle.get(); assertEquals("HOLA!", converter.convert(" holA!")); assertEquals(" HOLA!", converter.convertNoDelegation(" holA!")); + handle.destroy(); + assertTrue(TrimConverterDecorator.CONSTRUCTED.get()); + assertTrue(TrimConverterDecorator.DESTROYED.get()); } interface Converter { @@ -53,6 +63,9 @@ public String convertNoDelegation(String value) { @Decorator static class TrimConverterDecorator implements Converter { + static final AtomicBoolean CONSTRUCTED = new AtomicBoolean(); + static final AtomicBoolean DESTROYED = new AtomicBoolean(); + @Inject @Delegate Converter delegate; @@ -62,6 +75,16 @@ public String convert(String value) { return delegate.convert(value.trim()); } + @PostConstruct + void init() { + CONSTRUCTED.set(true); + } + + @PreDestroy + void destroy() { + DESTROYED.set(true); + } + } @Priority(2)