From 4f83ab734e829099bf5ce010eb07fb3035b89895 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Fri, 19 Mar 2021 21:36:35 +0100 Subject: [PATCH] ArC - fix the algorithm to find event parameter qualifiers - the Jandex MethodParameterInfo does not implement equals()/hashCode() and annotations declared on a parameter of the same method may have different MethodParameterInfo target instances - resolves #15886 --- .../io/quarkus/arc/processor/DisposerInfo.java | 2 +- .../io/quarkus/arc/processor/ObserverInfo.java | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java index 9712660d82827..175bae52a50ea 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/DisposerInfo.java @@ -86,7 +86,7 @@ Type getDisposedParameterType() { MethodParameterInfo initDisposedParam(MethodInfo disposerMethod) { List disposedParams = new ArrayList<>(); for (AnnotationInstance annotation : disposerMethod.annotations()) { - if (Kind.METHOD_PARAMETER.equals(annotation.target().kind()) && annotation.name().equals(DotNames.DISPOSES)) { + if (Kind.METHOD_PARAMETER == annotation.target().kind() && annotation.name().equals(DotNames.DISPOSES)) { disposedParams.add(annotation.target().asMethodParameter()); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java index 298109e92dbf1..b23b85a08b57b 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ObserverInfo.java @@ -1,5 +1,8 @@ package io.quarkus.arc.processor; +import static io.quarkus.arc.processor.Annotations.find; +import static io.quarkus.arc.processor.Annotations.getParameterAnnotations; + import io.quarkus.arc.processor.BuildExtension.BuildContext; import io.quarkus.arc.processor.ObserverTransformer.ObserverTransformation; import io.quarkus.arc.processor.ObserverTransformer.TransformationContext; @@ -36,9 +39,11 @@ public class ObserverInfo implements InjectionTargetInfo { static ObserverInfo create(BeanInfo declaringBean, MethodInfo observerMethod, Injection injection, boolean isAsync, List transformers, BuildContext buildContext, boolean jtaCapabilities) { MethodParameterInfo eventParameter = initEventParam(observerMethod, declaringBean.getDeployment()); - AnnotationInstance priorityAnnotation = observerMethod.annotation(DotNames.PRIORITY); + AnnotationInstance priorityAnnotation = find( + getParameterAnnotations(declaringBean.getDeployment(), observerMethod, eventParameter.position()), + DotNames.PRIORITY); Integer priority; - if (priorityAnnotation != null && priorityAnnotation.target().equals(eventParameter)) { + if (priorityAnnotation != null) { priority = priorityAnnotation.value().asInt(); } else { priority = ObserverMethod.DEFAULT_PRIORITY; @@ -285,10 +290,9 @@ static TransactionPhase initTransactionPhase(boolean isAsync, BeanDeployment bea static Set initQualifiers(BeanDeployment beanDeployment, MethodInfo observerMethod, MethodParameterInfo eventParameter) { Set qualifiers = new HashSet<>(); - for (AnnotationInstance annotation : beanDeployment.getAnnotations(observerMethod)) { - if (annotation.target().equals(eventParameter)) { - beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add); - } + for (AnnotationInstance annotation : getParameterAnnotations(beanDeployment, observerMethod, + eventParameter.position())) { + beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add); } return qualifiers; }