Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8080370

Method annotation added in abstract super method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P4 P4
    • None
    • 8u45
    • core-libs
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When I scan my compiled code to find a specific annotation I started to find duplicates when using Java8 in case the method annotated is the implementation of an abstract method where the input argument is included using generics.
      Here an example.

      My Annotation:
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.METHOD)
      public @interface ExampleAnnotation {}


      The abstract class:
      public abstract class AbstractExample<T extends BeanInterface> {
          public abstract void exampleMethod(T bean);
      }

      The Implementation:
      public class ImplementationExample extends AbstractExample<BeanImplementation>{
        @Override
        @ExampleAnnotation
        public void exampleMethod(BeanImplementation bean) {
        }
      }
      where BeanImplementation is an implementation of BeanInterface. If I compile the code using Java 8u45 and I list which methods of the ImplementationExample class have the annotation ExampleAnnotation using the following piece of code:

          Class<ImplementationExample> cls = ImplementationExample.class;
          List<Method> methods = new ArrayList<Method>();
          methods.addAll(Arrays.asList(cls.getDeclaredMethods()));

          for (Method method : methods) {
            System.out.println("method: " + method.getName() + " annotation: " + method.getAnnotation(ExampleAnnotation.class));
          }
      Then I get that both these methods:

      ImplementationExample.exampleMethod(BeanImplementation) ImplementationExample.exampleMethod(BeanInterface)

      have the annotation.

      If I use Java 7 or the Java 8 Eclipse Compiler then only the first method is annotated and this should be the correct behavior.

      Is this a bug in the java 8 compiler?


      REPRODUCIBILITY :
      This bug can be reproduced always.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: