Skip to content

Commit a995123

Browse files
author
Vincent Potucek
committed
[tryout fix] concurrency bug in NamespacedHierarchicalStore#computeIfAbsent(Object, Object, Function) #5171 #5209
Signed-off-by: Vincent Potucek <vpotucek@me.com>
1 parent 9fb8f11 commit a995123

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public void close() {
236236
* closed
237237
* @since 6.0
238238
*/
239-
@SuppressWarnings("ReferenceEquality")
240239
@API(status = MAINTAINED, since = "6.0")
241240
public <K, V> Object computeIfAbsent(N namespace, K key, Function<? super K, ? extends V> defaultCreator) {
242241
requireNonNull(defaultCreator);
@@ -245,7 +244,7 @@ public <K, V> Object computeIfAbsent(N namespace, K key, Function<? super K, ? e
245244
var result = StoredValue.evaluateIfNotNull(storedValue);
246245
if (result == null) {
247246
var newStoredValue = storedValues.compute(compositeKey, (__, oldStoredValue) -> {
248-
if (oldStoredValue == storedValue || oldStoredValue == null) {
247+
if (oldStoredValue == null || oldStoredValue.equals(storedValue)) {
249248
rejectIfClosed();
250249
return newStoredValue(new MemoizingSupplier(() -> {
251250
rejectIfClosed();
@@ -258,7 +257,7 @@ public <K, V> Object computeIfAbsent(N namespace, K key, Function<? super K, ? e
258257
return requireNonNull(newStoredValue.evaluate());
259258
}
260259
catch (Throwable t) { // remove failed entry to allow retry.
261-
if (newStoredValue == storedValues.get(compositeKey)) {
260+
if (newStoredValue.equals(storedValues.get(compositeKey))) {
262261
storedValues.remove(compositeKey, newStoredValue);
263262
}
264263
throw t;

0 commit comments

Comments
 (0)