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

2.0_EA_A : List::toArray succeeds with incorrectly typed array


    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:


      Name: dkC59003 Date: 05/17/99

      HotSpot does not pass the test below (return value is 97)
      in compiled mode (-Xcomp option is on): a list of Integer's converts to
      String array successfully (while the spec says about toArray(Object[] a)
      method: "Throws: ArrayStoreException - if the runtime type of the specified
      array is not a supertype of the runtime type of every element in this list.").

      $ java -version
      java version "1.2"
      HotSpot VM (2.0dev, mixed mode, build a)
      $ java -Xcomp b4210056
      Call succeeded with incorrectly typed array.
      $ echo $?

      The test is passed by classic, 2.0_ea1-A in mixed mode, 1.0fcs-E in compiled mode.
      Attempt to reduce run method to just try statement causes the test to pass.
      The same problem for win32 1.0_alpha2 release was reported by
      the bug #4210056 (integrated).

      ----------------------------------------------------------- b4210056.java
      import java.io.PrintStream;
      import java.util.*;

      public class b4210056 {

          static int listSize = 99;
          static String className = "java.util.ArrayList";

          public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);

          public static int run(String argv[], PrintStream out) {

      List list = sortedList(0, listSize);

      Integer[] intarrays[] = {new Integer[0],
      new Integer[listSize],
      new Integer[listSize+1], null};
      intarrays[3] = new Integer[listSize -1];

      for (int i=0; i<intarrays.length && intarrays[i] != null; i++) {
      Integer[] intarray = intarrays[i];
      boolean bigEnough = intarray.length >= listSize;
      boolean roomToSpare = intarray.length > listSize;
      if (roomToSpare)
      intarray[listSize] = new Integer(69);

      Integer[] intdump = (Integer[]) list.toArray(intarray);

      if (bigEnough != (intdump==intarray))
      return 2/*STATUS_FAILED*/;

      if (!bigEnough) { // Output array was allocated
      if (intdump.length != list.size())
      return 2/*STATUS_FAILED*/;

      if (intdump.getClass() != intarray.getClass())
      return 2/*STATUS_FAILED*/;

      if (roomToSpare && intarray[listSize] != null)
      return 2/*STATUS_FAILED*/;

      if (!list.equals((Arrays.asList(intdump)).subList(0, listSize)))
      return 2/*STATUS_FAILED*/;

      try {
      list = sortedList(0, listSize+1);
      list.toArray(new String[0]);
      out.println("Call succeeded with incorrectly typed array.");
      return 2;
      } catch (ArrayStoreException r) {
      return 0/*STATUS_PASSED*/;
          // Create a Sorted List containing Integers from from to to
          private static List sortedList(int from, int to) {
      List list = null;
      try {
      list = (List)(Class.forName(className).newInstance());
      for (int i=from; i<to; i++)
      list.add(new Integer(i));
      } catch(Throwable e) {
      throw new RuntimeException("Couldn't instantiate class " + e);
      return list;



          Issue Links



              • Assignee:
                cclicksunw Clifford Click (Inactive)
                dkhukhrosunw Dmitry Khukhro (Inactive)
              • Votes:
                0 Vote for this issue
                0 Start watching this issue


                • Created: