Skip to content

Commit 70bb7c4

Browse files
committed
Use Optional to trick JaCoCo on Travis
1 parent abaeb78 commit 70bb7c4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/ExtensionValuesStore.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.junit.platform.commons.util.ReflectionUtils.isAssignableTo;
1717

1818
import java.util.Objects;
19+
import java.util.Optional;
1920
import java.util.concurrent.ConcurrentHashMap;
2021
import java.util.concurrent.ConcurrentMap;
2122
import java.util.concurrent.locks.Lock;
@@ -77,12 +78,8 @@ <K, V> Object getOrComputeIfAbsent(Namespace namespace, K key, Function<K, V> de
7778
CompositeKey compositeKey = new CompositeKey(namespace, key);
7879
Supplier<Object> storedValue = getStoredValue(compositeKey);
7980
if (storedValue == null) {
80-
storedValue = new MemoizingSupplier(() -> defaultCreator.apply(key));
81-
Supplier<Object> previousValue = storedValues.putIfAbsent(compositeKey, storedValue);
82-
if (previousValue != null) {
83-
// There was a race condition, and we lost.
84-
storedValue = previousValue;
85-
}
81+
Supplier<Object> newValue = new MemoizingSupplier(() -> defaultCreator.apply(key));
82+
storedValue = Optional.ofNullable(storedValues.putIfAbsent(compositeKey, newValue)).orElse(newValue);
8683
}
8784
return storedValue.get();
8885
}

0 commit comments

Comments
 (0)