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

Class#getDeclaredMethods and AccessibleObject#isAnnotationPresent print wrong values

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      my code is follow:
      public interface IFly {

          String fly1();

          Object fly2();
      }

      public class FlyImpl implements IFly {
          @Override
          @FlyEnable
          public String fly1() {
              return null;
          }

          @Override
          @FlyEnable
          public String fly2() {
              return null;
          }
      }

      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.METHOD})
      @Documented
      public @interface FlyEnable {
      }

      public class Main {
          public static void main(String[] args) {
              //out 3, but i want 2
              //com.zj.IFly.fly2 should not be count
              System.out.println(FlyImpl.class.getDeclaredMethods().length);
              //is this is a bug? if this is not a bug, what should i do, then it out 2.

              for(Method method: FlyImpl.class.getDeclaredMethods()){
                  if( method.isAnnotationPresent( FlyEnable.class)){
                      // this out 3 times, but i want 2
                      // com.zj.IFly.fly2 call isAnnotationPresent( FlyEnable.class) should not return true
                      System.out.println("method:" + method.getName() + " is annotated by FlyEnable");
                      //is this is a bug? if this is not a bug, what should i do, com.zj.IFly.fly2 call isAnnotationPresent( FlyEnable.class) return false
                  }
              }
          }
      }

      i'm not good at English,
      If I say something wrong, don't be angry.

      REGRESSION : Last worked in version 8u202


      FREQUENCY : always


            rriggs Roger Riggs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: