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

Update documentation on Executable.getParameterAnnotations()

    Details

    • Subcomponent:
    • Resolved In Build:
      b108
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_17"
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux domU-12-31-36-00-39-52 2.6.18-xenU-ec2-v1.0 #2 SMP Mon Feb 18 14:28:43 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Constructor.getAnnotationParameters() returns an incorrect array when called on the constructor of an inner class with no parameters. According to the javadocs one would expect to get back an empty array, but instead what is returned is a singleton array containing as its element a single empty array.

      I looked in the source for Constructor.java and believe that this line is the problem is in line 1 of the method:

       public Annotation[][] getParameterAnnotations() {
              int numParameters = parameterTypes.length;
              if (parameterAnnotations == null)
                  return new Annotation[numParameters][0];

      It seems like numParameters should instead be set as:

             if [clazz is nested and non static
                  numParameters = parameterTypes.length - 1; // ignore implicit enclosing instance param
            else numParameters = parameterTypes.length




      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.*;
      import java.util.*;

      public
      class InnerClassTest
      {
          private
          class Inner1
          {
              private Inner1() {}
          }

          public
          static
          void
          main( String[] args )
              throws Exception
          {
              Constructor< ? > noArg = Inner1.class.getDeclaredConstructors()[ 0 ];
              System.out.println(
                  Arrays.deepToString( noArg.getParameterAnnotations() ) );
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      provide my own wrapper method to correct for this by only calling Constructor.getParameterAnnotations in cases when that method will return a correct result and supplying an empty array on its own otherwise

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emc Eric Mccorkle
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: