On Tue, Jun 30, 2015 at 3:02 AM, Paul Sandoz <paul.san...@oracle.com> wrote:
> > On Jun 26, 2015, at 11:54 PM, Martin Buchholz <marti...@google.com> wrote: > > > 10 years later ... still asking for approval to commit. > > > > https://bugs.openjdk.java.net/browse/JDK-6260652 > > > http://cr.openjdk.java.net/~martin/webrevs/openjdk9/Arrays.asList.toArray/ > > +1. > > This is probably why there is still the following code in ArrayList: > > public ArrayList(Collection<? extends E> c) { > elementData = c.toArray(); > if ((size = elementData.length) != 0) { > // c.toArray might (incorrectly) not return Object[] (see 6260652) > if (elementData.getClass() != Object[].class) > elementData = Arrays.copyOf(elementData, size, Object[].class); > } else { > // replace with empty array. > this.elementData = EMPTY_ELEMENTDATA; > } > } > I recall also being the author of that comment. I suspect we cannot remove this check, Agreed. > but we could update the comment referring to JDK-external collection > implementations. > > The comment remains correct even if 6260652 is fixed. I can't think up a clearly better one. > I trawled through the JDK code and found one other violation of the > toArray contract in: > > com.sun.java.util.jar.pack.ConstantPool.Index: > > public Entry[] toArray() { > return toArray(new Entry[size()]); > } > Agreed. I'm unfamiliar with that code - it should probably be fixed in another change.