Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Magne
Votes: 0
Watchers: 1

If you were logged in you would be able to see more operations.

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

Created: 06/Jun/11 07:10 PM   Updated: 06/Jun/11 08:45 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide

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:
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()]);
        // 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]);

Magne added a comment - 06/Jun/11 07:11 PM

This is under current version, 5.5.1

dautelle added a comment - 06/Jun/11 08:45 PM

Please resubmit on
Javolution has been moved from kenai to