FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The replaceAll method of a list returned by java.util.Collections.checkedList passes the replacement operator directly to the underlying list, enabling violation of the type checking.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
import java.util.function.UnaryOperator;
class CheckedListViolationBug {
public static void main(String... args) {
// Create a runtime-checked List of Integers only
List<Integer> integersOnly = Collections.checkedList(new ArrayList<>(), Integer.class);
integersOnly.add(1);
integersOnly.add(2);
integersOnly.add(3);
// the UnaryOperator bypasses the check, enabling insertion of arbitrary elements
integersOnly.replaceAll((UnaryOperator)(e -> "ha!"));
// the list now contains Strings:
System.out.println(integersOnly);
}
}
---------- END SOURCE ----------