Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@PostConstruct and @PreDestroy support on @Decorator classes #36545

Closed
nahguam opened this issue Oct 18, 2023 · 1 comment · Fixed by #36556
Closed

@PostConstruct and @PreDestroy support on @Decorator classes #36545

nahguam opened this issue Oct 18, 2023 · 1 comment · Fixed by #36556
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Milestone

Comments

@nahguam
Copy link
Contributor

nahguam commented Oct 18, 2023

Describe the bug

@PostConstruct methods are honoured on @Decorator classes but@PreDestroy methods are not.

Expected behavior

If a valid pre-destroy method is present on a decorator class it is invoked on application shutdown.

Actual behavior

The decorator pre-destroy method is not invoked

How to Reproduce?

  1. Create a new Quarkus app: quarkus create app
  2. Implement bean and decorator:
package org.acme;

import io.quarkus.logging.Log;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Priority;
import jakarta.decorator.Decorator;
import jakarta.decorator.Delegate;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Any;
import jakarta.inject.Inject;

interface DecoratorReproducer {
    interface Foo {
        String foo();
    }

    @ApplicationScoped
    class FooImpl implements Foo {
        @Override
        public String foo() {
            return "foo";
        }

        @PostConstruct
        void postConstruct() {
            Log.info("PostConstruct");
        }

        @PreDestroy
        void preDestroy() {
            Log.info("PreDestroy");
        }
    }

    @Decorator
    @Priority(0)
    class FooDecorator implements Foo {
        @Inject
        @Any
        @Delegate
        Foo foo;

        @Override
        public String foo() {
            Log.info("foo");
            return foo.foo();
        }

        @PostConstruct
        void postConstruct() {
            Log.info("PostConstruct");
        }

        @PreDestroy
        void preDestroy() {
            Log.info("PreDestroy");
        }
    }
}
  1. Inject bean into GreetingResource:
@Path("/hello")
public class GreetingResource {
    @Inject
    Foo foo;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return foo.foo();
    }
}
  1. Start the app: quarkus dev
  2. In another terminal: curl localhost:8080/hello
  3. Observe the logs (post-construct is invoked on the bean & decorator):
INFO  [org.acm.DecoratorReproducer$FooDecorator] (executor-thread-1) PostConstruct
INFO  [org.acm.DecoratorReproducer$FooImpl] (executor-thread-1) PostConstruct
INFO  [org.acm.DecoratorReproducer$FooDecorator] (executor-thread-1) foo
  1. Shutdown the app: [h], [q]
  2. Observe the logs (pre-destroy is invoked on the bean only):
INFO  [org.acm.DecoratorReproducer$FooImpl] (Shutdown thread) PreDestroy
INFO  [io.quarkus] (Shutdown thread) code-with-quarkus stopped in 0.018s

Output of uname -a or ver

Darwin [snip] 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6020 arm64

Output of java -version

openjdk version "11.0.19" 2023-04-18 OpenJDK Runtime Environment Temurin-11.0.19+7 (build 11.0.19+7) OpenJDK 64-Bit Server VM Temurin-11.0.19+7 (build 11.0.19+7, mixed mode)

GraalVM version (if different from Java)

n/a

Quarkus version or git rev

3.4.3

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.8 (4c87b05d9aedce574290d1acc98575ed5eb6cd39) Maven home: [snip]/.m2/wrapper/dists/apache-maven-3.8.8-bin/67c30f74/apache-maven-3.8.8 Java version: 17.0.7, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "13.6", arch: "aarch64", family: "mac"

Additional information

No response

@nahguam nahguam added the kind/bug Something isn't working label Oct 18, 2023
@Ladicek Ladicek added area/arc Issue related to ARC (dependency injection) and removed triage/needs-triage labels Oct 18, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 18, 2023

/cc @manovotn (arc), @mkouba (arc)

mkouba added a commit to mkouba/quarkus that referenced this issue Oct 18, 2023
@quarkus-bot quarkus-bot bot added this to the 3.6 - main milestone Oct 19, 2023
@gsmet gsmet modified the milestones: 3.6 - main, 3.5.1 Oct 26, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 26, 2023
@aloubyansky aloubyansky modified the milestones: 3.5.1, 3.2.8.Final Nov 2, 2023
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Nov 2, 2023
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants