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

(anno) Method.getAnnotations() ignores inherited annotations

    Details

    • Subcomponent:
    • Resolved In Build:
      rc
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: viR10068 Date: 01/26/2004


      The metadata-public-draft.html says for the methods Method.getDeclaredAnnotations():
      "Returns all annotations that are directly present on this element.
      Unlike the other methods in this interface, this method ignores
      inherited annotations."
      and for the meta-attribute Inherited:
      "Note that this meta-annotation type has no effect if the annotated
      type is used to annotate anything other than a class or instance method
      declaration."
       
      So the method Method.getAnnotations() should not ingnore inherited annotations.
      But jdk1.5.0-b35 ignores inherited annotations for methods.

      Affected test is:
      api/java_lang/reflect/AccessibleObject/index.html#getAnnotations[getAnnotations0006]

      Simplified version of the test:
      --------------------------- B2.java -----------------------------------
      import java.io.PrintStream;

      import java.lang.annotation.Inherited;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;

      @Inherited @Retention(RetentionPolicy.RUNTIME) @interface testInter1 {
          String str_value();
      }
      @Inherited @Retention(RetentionPolicy.RUNTIME) @interface testInter2 {
          String str_value();
      }

      class annotElem0001 {
          @testInter1(str_value = "m1") void m() {};
      }

      class B2 extends annotElem0001 {

          @testInter2(str_value = "m2") void m() {};

          public static void main(String args[]) {
              try {
                  System.out.println("length = '" +
      B2.class.getDeclaredMethod("m").getAnnotations().length + "' " +
      B2.class.getDeclaredMethod("m").getAnnotations()[0] );
              } catch (Exception e) {
                  System.out.println("Unexpected result " + e);
              }
          }
      }
      -------------------------------------------------------------------------

      Execution log:
      % jdk1.5.0-b35/solaris-sparc/bin/javac -version -source 1.5 -target 1.5 B2.java &&
      jdk1.5.0-b35/solaris-sparc/bin/java -Xfuture B2
      javac 1.5.0-beta2
      length = '1' @testInter2(str_value=m2)
      %

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              gbrachasunw Gilad Bracha (Inactive)
              Reporter:
              vivsunw Viv Viv (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: