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

Collection.toArray(Object[]) has ambiguous spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2
    • core-libs
    • beta
    • generic
    • generic
    • Verified

      The spec for Collection.toArray(Object[]) is unclear on what happens when collection elements are not assignment compatible with the array element type. Worse, it seems to imply that *all* elements that are assignment compatible will be returned. In fact the implementations currently just bail the first time an element can't be stuffed in the array. The spec for AbstractCollection.toArray(Object[]) is somewhat better (though grammatically incorrect).

      At the very least, the specs for Collection and AbstractCollection and all of the general purpose implementations should be brought into accord, and none should appear to promise something that they don't deliver.

      Perhaps we should tighten up the behavior as well, and clarify the spec to indicate that *all* elements of appropriate type will be returned even if one or more are not of appropriate type. I'm not sure...

            jjb Josh Bloch (Inactive)
            jjb Josh Bloch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: