RFR: 8047795: Collections.checkedList checking bypassed by List.replaceAll (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Tue Jun 24 08🔞39 UTC 2014


On Jun 24, 2014, at 2:42 AM, Mike Duigou <mike.duigou at oracle.com> wrote:

Hello all;

This changeset corrects a reported problem with the lists returned by Collections.checkedList(). Since Java 8 the replaceAll() method on checked lists has erroneously allowed the operator providing replacements to provide illegal replacement values which are then stored, unchecked into the wrapped list. This changeset adds a check on the proposed replacement value and throws a ClassCastException if the replacement value is incompatible with the list.

That seems like a reasonable approach and it's in sync with the behaviour of Map.replaceAll.

Additionally the javadoc is updated to inform users that a ClassCastException may result if the proposed replacement is unacceptable.

No users will see the JavaDoc on Collections.CheckedList since it is package private, plus i think it redundant. Any such associated documentation would need to be on the public static method, and i am not sure we really need to say anything more than what is already said:

3388 * Any attempt to insert an element of the wrong type will result in 3389 * an immediate {@link ClassCastException}. Assuming a list contains

Note that this changeset takes the strategy of failing when the illegal value is encountered. Replacements of earlier items in the list are retained.

jbsbug: https://bugs.openjdk.java.net/browse/JDK-8047795 webrev: http://cr.openjdk.java.net/~mduigou/JDK-8047795/0/webrev/

Are there existing tests for the checked Map.replaceAll (for keys and values)?

Paul.

This change will be backported to Java 8.

Mike



More information about the core-libs-dev mailing list