105 ((Map.Entry)(m.entrySet().iterator().next())).setValue(v2);
106 assertSame(v2, m.get(k));
107 assertTrue(m.containsKey(k));
108 assertTrue(m.containsValue(v2));
109 assertFalse(m.containsValue(v1));
110 } else {
111 assertThrows(UnsupportedOperationException.class,
112 () -> ((Map.Entry)(m.entrySet().iterator().next())).setValue(v2));
113 }
114 }
115 }
116
117 /**
118 * Tests and extends the scenario reported in
119 * https://bugs.openjdk.java.net/browse/JDK-8186171
120 * HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
121 * ant -Djsr166.tckTestClass=HashMapTest -Djsr166.methodFilter=testBug8186171 -Djsr166.runsPerTest=1000 tck
122 */
123 public void testBug8186171() {
124 if (!impl.supportsSetValue()) return;
125 final ThreadLocalRandom rnd = ThreadLocalRandom.current();
126 final boolean permitsNullValues = impl.permitsNullValues();
127 final Object v1 = (permitsNullValues && rnd.nextBoolean())
128 ? null : impl.makeValue(1);
129 final Object v2 = (permitsNullValues && rnd.nextBoolean() && v1 != null)
130 ? null : impl.makeValue(2);
131
132 // If true, always lands in first bucket in hash tables.
133 final boolean poorHash = rnd.nextBoolean();
134 class Key implements Comparable<Key> {
135 final int i;
136 Key(int i) { this.i = i; }
137 public int hashCode() { return poorHash ? 0 : super.hashCode(); }
138 public int compareTo(Key x) {
139 return Integer.compare(this.i, x.i);
140 }
141 }
142
143 // Both HashMap and ConcurrentHashMap have:
144 // TREEIFY_THRESHOLD = 8; UNTREEIFY_THRESHOLD = 6;
|
105 ((Map.Entry)(m.entrySet().iterator().next())).setValue(v2);
106 assertSame(v2, m.get(k));
107 assertTrue(m.containsKey(k));
108 assertTrue(m.containsValue(v2));
109 assertFalse(m.containsValue(v1));
110 } else {
111 assertThrows(UnsupportedOperationException.class,
112 () -> ((Map.Entry)(m.entrySet().iterator().next())).setValue(v2));
113 }
114 }
115 }
116
117 /**
118 * Tests and extends the scenario reported in
119 * https://bugs.openjdk.java.net/browse/JDK-8186171
120 * HashMap: Entry.setValue may not work after Iterator.remove() called for previous entries
121 * ant -Djsr166.tckTestClass=HashMapTest -Djsr166.methodFilter=testBug8186171 -Djsr166.runsPerTest=1000 tck
122 */
123 public void testBug8186171() {
124 if (!impl.supportsSetValue()) return;
125 if (!atLeastJava10()) return; // jdk9 is no longer maintained
126 final ThreadLocalRandom rnd = ThreadLocalRandom.current();
127 final boolean permitsNullValues = impl.permitsNullValues();
128 final Object v1 = (permitsNullValues && rnd.nextBoolean())
129 ? null : impl.makeValue(1);
130 final Object v2 = (permitsNullValues && rnd.nextBoolean() && v1 != null)
131 ? null : impl.makeValue(2);
132
133 // If true, always lands in first bucket in hash tables.
134 final boolean poorHash = rnd.nextBoolean();
135 class Key implements Comparable<Key> {
136 final int i;
137 Key(int i) { this.i = i; }
138 public int hashCode() { return poorHash ? 0 : super.hashCode(); }
139 public int compareTo(Key x) {
140 return Integer.compare(this.i, x.i);
141 }
142 }
143
144 // Both HashMap and ConcurrentHashMap have:
145 // TREEIFY_THRESHOLD = 8; UNTREEIFY_THRESHOLD = 6;
|