Repository: quarkusio/quarkus
Issue: BeanManager.resolveInterceptors() does not work correctly

The method or constructor must have all the interceptor bindings of the interceptor and not vice versa. See https://github.com/quarkusio/quarkus/blob/master/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java#L496-L504.

Changed files:
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Qualifiers.java
independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/beanmanager/BeanManagerTest.java
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java

diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java
index 7a41180e57b..c5aa15a07e5 100644
--- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java
+++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ArcContainerImpl.java
@@ -494,9 +494,11 @@ List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... in
     }
 
     private boolean hasAllInterceptionBindings(InjectableInterceptor<?> interceptor, Annotation[] interceptorBindings) {
-        for (Annotation binding : interceptorBindings) {
+        // The method or constructor has all the interceptor bindings of the interceptor
+        List<Annotation> bindings = Arrays.asList(interceptorBindings);
+        for (Annotation binding : interceptor.getInterceptorBindings()) {
             // The resolution rules are the same for qualifiers
-            if (!Qualifiers.hasQualifier(interceptor.getInterceptorBindings(), binding)) {
+            if (!Qualifiers.hasQualifier(bindings, binding)) {
                 return false;
             }
         }
diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Qualifiers.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Qualifiers.java
index b9a7ea50c35..026b7575529 100644
--- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Qualifiers.java
+++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/Qualifiers.java
@@ -42,30 +42,10 @@ static boolean hasQualifiers(InjectableBean<?> bean, Annotation... requiredQuali
     }
 
     static boolean hasQualifier(InjectableBean<?> bean, Annotation requiredQualifier) {
-
-        Class<? extends Annotation> requiredQualifierClass = requiredQualifier.annotationType();
-        Method[] members = requiredQualifierClass.getDeclaredMethods();
-
-        for (Annotation qualifier : bean.getQualifiers()) {
-            Class<? extends Annotation> qualifierClass = qualifier.annotationType();
-            if (qualifierClass.equals(requiredQualifier.annotationType())) {
-                boolean matches = true;
-                for (Method value : members) {
-                    if (!value.isAnnotationPresent(Nonbinding.class)
-                            && !invoke(value, requiredQualifier).equals(invoke(value, qualifier))) {
-                        matches = false;
-                        break;
-                    }
-                }
-                if (matches) {
-                    return true;
-                }
-            }
-        }
-        return false;
+        return hasQualifier(bean.getQualifiers(), requiredQualifier);
     }
 
-    static boolean hasQualifier(Set<Annotation> qualifiers, Annotation requiredQualifier) {
+    static boolean hasQualifier(Iterable<Annotation> qualifiers, Annotation requiredQualifier) {
 
         Class<? extends Annotation> requiredQualifierClass = requiredQualifier.annotationType();
         Method[] members = requiredQualifierClass.getDeclaredMethods();
diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/beanmanager/BeanManagerTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/beanmanager/BeanManagerTest.java
index 8b12b42de30..953abe88322 100644
--- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/beanmanager/BeanManagerTest.java
+++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/beanmanager/BeanManagerTest.java
@@ -157,6 +157,7 @@ public Annotated getAnnotated() {
         assertNull(injectableReference.injectionPoint.getBean());
     }
 
+    @SuppressWarnings("serial")
     @Test
     public void testResolveInterceptors() {
         BeanManager beanManager = Arc.container().beanManager();
@@ -165,7 +166,9 @@ public void testResolveInterceptors() {
         interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT, new DummyBinding.Literal(true, true));
         assertTrue(interceptors.isEmpty());
         // alpha is @Nonbinding
-        interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, new DummyBinding.Literal(false, true));
+        interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, new DummyBinding.Literal(false, true),
+                new AnnotationLiteral<UselessBinding>() {
+                });
         assertEquals(2, interceptors.size());
         assertEquals(DummyInterceptor.class, interceptors.get(0).getBeanClass());
         assertEquals(LowPriorityInterceptor.class, interceptors.get(1).getBeanClass());
@@ -256,6 +259,14 @@ public boolean bravo() {
 
     }
 
+    @Target({ TYPE, METHOD })
+    @Retention(RUNTIME)
+    @Documented
+    @InterceptorBinding
+    public @interface UselessBinding {
+
+    }
+
     @DummyBinding(alpha = true, bravo = true)
     @Priority(10)
     @Interceptor