From 4c25b68e63f9966fdc12c8000d7273c49c5d4744 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 22 Feb 2023 17:09:38 +0100 Subject: [PATCH 1/2] Arc - Validate whether interceptors declare producer methods --- .../arc/processor/InterceptorInfo.java | 16 ++++ .../illegal/DisposerInInterceptorTest.java | 73 ++++++++++++++++++ .../ProducerFieldInInterceptorTest.java | 73 ++++++++++++++++++ .../ProducerMethodInInterceptorTest.java | 76 +++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/illegal/DisposerInInterceptorTest.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/illegal/ProducerFieldInInterceptorTest.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/illegal/ProducerMethodInInterceptorTest.java diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java index 2438fe6045ac9..444f04ec4807a 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java @@ -9,12 +9,14 @@ import java.util.List; import java.util.Set; +import jakarta.enterprise.inject.spi.DefinitionException; import jakarta.enterprise.inject.spi.InterceptionType; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; +import org.jboss.jandex.FieldInfo; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; import org.jboss.jandex.Type.Kind; @@ -57,6 +59,12 @@ public class InterceptorInfo extends BeanInfo implements Comparable Date: Thu, 23 Feb 2023 11:17:25 +0100 Subject: [PATCH 2/2] Arc - Change InterceptorInfo to use AnnotationStore instead of querying Jandex directly --- .../io/quarkus/arc/processor/AnnotationStore.java | 2 +- .../io/quarkus/arc/processor/InterceptorInfo.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationStore.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationStore.java index 67e4fc4c78e37..dc3557562f721 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationStore.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationStore.java @@ -114,7 +114,7 @@ private Collection getOriginalAnnotations(AnnotationTarget t Collection annotations; switch (target.kind()) { case CLASS: - annotations = target.asClass().classAnnotations(); + annotations = target.asClass().declaredAnnotations(); break; case METHOD: // Note that the returning collection also contains method params annotations diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java index 444f04ec4807a..79b90f70aa15a 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java @@ -48,6 +48,7 @@ public class InterceptorInfo extends BeanInfo implements Comparable(), injections, null, null, false, Collections.emptyList(), null, false, null, priority); this.bindings = bindings; + AnnotationStore store = beanDeployment.getAnnotationStore(); List aroundInvokes = new ArrayList<>(); List aroundConstructs = new ArrayList<>(); List postConstructs = new ArrayList<>(); @@ -59,28 +60,28 @@ public class InterceptorInfo extends BeanInfo implements Comparable