Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2551

Interface default methods are treated inconsistently by AnnotatedType and WithAnnotations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 3.1.0.Final
    • 3.0.5.Final
    • Extensions
    • None
    • Hide

      I have a class `MyBean` which implements an interface `MyInterface` and `MyInterface` declares a default method `myMethod()` which is annotated `@MyAnnotation`.

      If I observe the `ProcessAnnotatedType` event for `MyBean`, I can call `getAnnotatedType().getMethods()` and see the default method inherited from `MyInterface`.

      However, if I observe the `ProcessAnnotatedType` event but constrain it using `@WithAnnotations(MyAnnotation.class)`, my observer method is not called.

      Show
      I have a class `MyBean` which implements an interface `MyInterface` and `MyInterface` declares a default method `myMethod()` which is annotated `@MyAnnotation`. If I observe the `ProcessAnnotatedType` event for `MyBean`, I can call `getAnnotatedType().getMethods()` and see the default method inherited from `MyInterface`. However, if I observe the `ProcessAnnotatedType` event but constrain it using `@WithAnnotations(MyAnnotation.class)`, my observer method is not called.

      AnnotatedType.getMethods() returns default methods inherited from interfaces, but @WithAnnotations does not consider annotations on these methods when selecting types for the ProcessAnnotatedType event.

      The Javadoc for WithAnnotations seems to say it should be consistent with spec section 11.4. Alternative Metadata Sources which includes the description of AnnotatedType.getMethods().

      Section 11.4 only talks about methods from the class and its superclasses and makes no mention of default methods from interfaces.

      I'm not sure whether default methods inherited from interfaces should be included here, but I would expect AnnotatedType.getMethods() and WithAnnotations to be consistent.

            mkouba@redhat.com Martin Kouba
            azquelt Andrew Rouse
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: