javolution
  1. javolution
  2. JAVOLUTION-7

FastMap.toArray(T[] array) breaks with List

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Labels:
      None

      Description

      The List interface specifies the following for the List.toArray(T[] t) method:

      Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. JAVA 6 API

      FastList breaks this, and throws a java.lang.UnsupportedOperationException: Destination array too small if the supplied array is to small.

      The following code demonstrates the issue:

      FastMapTest.java
      import javolution.util.FastList;
      
      public class FastMapTest {
          public static void main(String[] args) {
              FastList<String> list = new FastList<String>();
              list.add("A text string");
              list.add("A different text string");
              // works
              System.out.print("list.toArray(new String[list.size()]) :: ");
              list.toArray(new String[list.size()]);
              System.out.println("OK");
              // throws java.lang.UnsupportedOperationException, should be used only to derive the type of the returned array.
              System.out.print("list.toArray(new String[0]) :: ");
              list.toArray(new String[0]);
              System.out.println("OK");
          }
      }
      

        Activity

        Hide
        Magne added a comment -

        This is under current version, 5.5.1

        Show
        Magne added a comment - This is under current version, 5.5.1
        Hide
        dautelle added a comment -

        Please resubmit on http://java.net/projects/javolution
        Javolution has been moved from kenai to java.net
        Thanks.

        Show
        dautelle added a comment - Please resubmit on http://java.net/projects/javolution Javolution has been moved from kenai to java.net Thanks.

          People

          • Assignee:
            Unassigned
            Reporter:
            Magne
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: