author | vlivanov |
Wed, 02 Mar 2016 15:42:03 +0300 | |
changeset 36349 | 6cc8e6f596b2 |
parent 32649 | 2ee9017c7597 |
child 40684 | 2e37c119dc2a |
permissions | -rw-r--r-- |
29743
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
1 |
/* |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
2 |
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
4 |
* |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
10 |
* |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
15 |
* accompanied this code). |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
16 |
* |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
20 |
* |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
23 |
* questions. |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
24 |
*/ |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
25 |
import java.util.Arrays; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
26 |
import java.util.ConcurrentModificationException; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
27 |
import java.util.HashMap; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
28 |
import java.util.Hashtable; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
29 |
import java.util.Iterator; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
30 |
import java.util.LinkedHashMap; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
31 |
import java.util.Map; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
32 |
import java.util.function.BiFunction; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
33 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
34 |
import org.testng.annotations.Test; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
35 |
import org.testng.annotations.DataProvider; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
36 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
37 |
/** |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
38 |
* @test |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
39 |
* @bug 8071667 |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
40 |
* @summary Ensure that ConcurrentModificationExceptions are thrown as specified from Map methods that accept Functions |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
41 |
* @author bchristi |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
42 |
* @build Defaults |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
43 |
* @run testng FunctionalCMEs |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
44 |
*/ |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
45 |
public class FunctionalCMEs { |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
29743
diff
changeset
|
46 |
static final String KEY = "key"; |
29743
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
47 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
48 |
@DataProvider(name = "Maps", parallel = true) |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
49 |
private static Iterator<Object[]> makeMaps() { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
50 |
return Arrays.asList( |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
51 |
// Test maps that CME |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
52 |
new Object[]{new HashMap<>(), true}, |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
53 |
new Object[]{new Hashtable<>(), true}, |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
54 |
new Object[]{new LinkedHashMap<>(), true}, |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
55 |
// Test default Map methods - no CME |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
56 |
new Object[]{new Defaults.ExtendsAbstractMap<>(), false} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
57 |
).iterator(); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
58 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
59 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
60 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
61 |
public void testComputeIfAbsent(Map<String,String> map, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
62 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
63 |
map.computeIfAbsent(KEY, k -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
64 |
putToForceRehash(map); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
65 |
return "computedValue"; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
66 |
}); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
67 |
}, expectCME); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
68 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
69 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
70 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
71 |
public void testCompute(Map<String,String> map, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
72 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
73 |
map.compute(KEY, mkBiFunc(map)); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
74 |
}, expectCME); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
75 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
76 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
77 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
78 |
public void testComputeWithKeyMapped(Map<String,String> map, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
79 |
map.put(KEY, "firstValue"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
80 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
81 |
map.compute(KEY, mkBiFunc(map)); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
82 |
}, expectCME); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
83 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
84 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
85 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
86 |
public void testComputeIfPresent(Map<String,String> map, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
87 |
map.put(KEY, "firstValue"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
88 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
89 |
map.computeIfPresent(KEY, mkBiFunc(map)); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
90 |
}, expectCME); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
91 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
92 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
93 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
94 |
public void testMerge(Map<String,String> map, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
95 |
map.put(KEY, "firstValue"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
96 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
97 |
map.merge(KEY, "nextValue", mkBiFunc(map)); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
98 |
}, expectCME); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
99 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
100 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
101 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
102 |
public void testForEach(Map<String,String> map, boolean ignored) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
103 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
104 |
map.put(KEY, "firstValue"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
105 |
putToForceRehash(map); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
106 |
map.forEach((k,v) -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
107 |
map.remove(KEY); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
108 |
}); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
109 |
}, true); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
110 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
111 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
112 |
@Test(dataProvider = "Maps") |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
113 |
public void testReplaceAll(Map<String,String> map, boolean ignored) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
114 |
checkCME(() -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
115 |
map.put(KEY, "firstValue"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
116 |
putToForceRehash(map); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
117 |
map.replaceAll((k,v) -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
118 |
map.remove(KEY); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
119 |
return "computedValue"; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
120 |
}); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
121 |
},true); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
122 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
123 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
124 |
private static void checkCME(Runnable code, boolean expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
125 |
try { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
126 |
code.run(); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
127 |
} catch (ConcurrentModificationException cme) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
128 |
if (expectCME) { return; } else { throw cme; } |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
129 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
130 |
if (expectCME) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
131 |
throw new RuntimeException("Expected CME, but wasn't thrown"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
132 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
133 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
134 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
135 |
private static BiFunction<String,String,String> mkBiFunc(Map<String,String> map) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
136 |
return (k,v) -> { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
137 |
putToForceRehash(map); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
138 |
return "computedValue"; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
139 |
}; |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
140 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
141 |
|
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
142 |
private static void putToForceRehash(Map<String,String> map) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
143 |
for (int i = 0; i < 64; ++i) { |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
144 |
map.put(i + "", "value"); |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
145 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
146 |
} |
981893a47bec
8071667: HashMap.computeIfAbsent() adds entry that HashMap.get() does not find.
bchristi
parents:
diff
changeset
|
147 |
} |