Collection.toArray implementations do not conform to Java API docs

Description

Per http://docs.oracle.com/javase/6/docs/api/index.html?java/util/Collections.html, Collection.toArray(T []) implements must allocate an array of type T[], not Object[]. This will cause type-casty code to break. Not often a problem in Clojure, but e.g. it makes Clojure defrecords unprintable from the JRuby console.

There is also a chance to DRY up some common code, as the six places that have this problem should all call an RT helper.

This also fixes toArray(T[]) for PersistentQueue when the passed array has the same length as the queue.

Environment

None

Attachments

5

Activity

Show:

Stuart Halloway February 20, 2012 at 1:17 AM

Aargh. One last time with correct git usage. Ignore take-4, the take-5 patch applies on master.

Stuart Halloway February 20, 2012 at 12:48 AM

the take 4 patch is the same as previous, merely cleaned up to apply on master

Cosmin Stejerean February 4, 2012 at 12:52 AM

One more shot at getting a combined patch for this issue. 0001-CLJ-895.-Use-RT.seqToPassedArray-to-implement-Collec.patch contains the fix as well as the tests and should apply with no problems on top of e27a27d9a6dc3fd0d15f26a5076e2876007e0ae6

Cosmin Stejerean December 16, 2011 at 10:20 PM

Odd, it seems to apply cleanly for me onto 485b6fc357157458f156bbba49f8e78c10c66c31 as well as 12f07da889819bc5613546ec223e97ac27c86dbf (current HEAD).

Stuart Sierra December 16, 2011 at 3:30 PM

Patch 0895-to-array-take-3.patch does not apply on 485b6fc357157458f156bbba49f8e78c10c66c31

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Created December 10, 2011 at 11:27 PM
Updated March 1, 2013 at 6:47 PM
Resolved March 1, 2013 at 6:47 PM