Specification for Collections.nCopies() says:
"Returns an immutable list consisting of n copies of the specified object."
However its iterator doesn't throw UOE, but throws ISE and calling of method removeIf(alwaysFalse) doesn't lead to the expected UnsupportedOperationException.
http://download.java.net/jdk8/docs/api/java/util/Collection.html#removeIf(java.util.function.Predicate)
"Throws:
UnsupportedOperationException - if the remove method is not supported by this collection's iterator()"
Please see the following code sample:
final List<String> nCopies = Collections.nCopies(3, "a");
try {
nCopies.iterator().remove();
} catch (UnsupportedOperationException uoe) {
System.out.println("OK, remove method is not supported");
} catch (Exception e) {
System.out.println("e = " + e);
}
nCopies.removeIf( e -> false);
The output will be:
e = java.lang.IllegalStateException
The following JCK test will fail:
api/java_util/Collections/ncopies/RemoveIf.html#RemoveIf[elementRemovalNotSupported]