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

(reflect) please retrofit varargs onto Array.newInstance

    Details

    • Subcomponent:
    • Resolved In Build:
      b63
    • CPU:
      generic
    • OS:
      generic, solaris_8
    • Verification:
      Verified

      Description

      The following method can usefully be retrofitted with varargs:

      public static
      Object java.lang.reflect.Array.newInstance(
          Class<?> componentType,
          int... dimensions);
      See below for the suggested fix and JUnit testcase:

      A DESCRIPTION OF THE FIX :
      version :
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b54)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b54, mixed mode, sharing)

      diff -u :
      --- Array.java.old Wed Oct 12 14:58:53 2005
      +++ Array.java.new Wed Oct 12 15:01:40 2005
      @@ -85,7 +85,7 @@
            * @exception NegativeArraySizeException if any of the components in
            * the specified <code>dimensions</code> argument is negative.
            */
      - public static Object newInstance(Class<?> componentType, int[] dimensions)
      + public static Object newInstance(Class<?> componentType, int... dimensions)
              throws IllegalArgumentException, NegativeArraySizeException {
              return multiNewArray(componentType, dimensions);
           }


      JUnit TESTCASE :
      /** javac -Xbootclasspath/p:. Path5041975Test.java
       * java -Xbootclasspath/p:. Path5041975Test
       * @author remi
       */
      public class Path5041975Test {
        public static void main(String[] args) {
          Object array=Array.newInstance(String.class, 2,3);
          if (!(array instanceof String[][]))
            throw new AssertionError("erreor in newInstance");
        }
      }

      FIX FOR BUG NUMBER:
      5041975

        Attachments

          Activity

            People

            • Assignee:
              darcy Joe Darcy
              Reporter:
              gafter Neal Gafter
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: