Hi Stuart,
The test looks good, but the way you write keys from unmodifiable map
composed of WORDS:
84 Arrays.stream(WORDS)
85 .collect(toUnmodifiableMap(word -> word, word ->
""))
86 .keySet()
87 .forEach(mapOut::println);
...could actually randomize order because of the way the collector
constructs the unmodifiable map and not because of the unmodifiable map
API itself:
Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ?
extends K> keyMapper,
Function<? super T, ?
extends U> valueMapper,
BinaryOperator<U> mergeFunction) {
Objects.requireNonNull(keyMapper, "keyMapper");
Objects.requireNonNull(valueMapper, "valueMapper");
Objects.requireNonNull(mergeFunction, "mergeFunction");
return collectingAndThen(
toMap(keyMapper, valueMapper, mergeFunction, HashMap::new),
map ->
(Map<K,U>)Map.ofEntries(map.entrySet().toArray(new Map.Entry[0])));
}
If for example HashMap did order randomization and unmodifiable map
didn't, the test would still pass.
So you should perhaps construct an Map.Entry[] form WORDS keeping
encounter order and initialize the unmodifiable map from it directly.
Regards, Peter
On 05/24/2018 02:26 AM, Stuart Marks wrote:
Hi all,
Please review this new test for testing the randomized iteration order
of unmodifiable Set and Map implementations.
Bug:
https://bugs.openjdk.java.net/browse/JDK-8201518
Webrev:
http://cr.openjdk.java.net/~smarks/reviews/8201518/webrev.0/
Thanks,
s'marks