8387722: The race during initialization or lazy constants in and Map/Set

Reviewed-by: jvernee
This commit is contained in:
Per Minborg 2026-07-25 07:54:18 +00:00
parent 97544c7ede
commit 3412d4c0dd

View File

@ -675,6 +675,12 @@ final class LazyCollections {
final long offset = offsetFor(index);
final Object mutex = mutexes.acquireMutex(offset);
if (mutex == null) {
// There might be a race where the value is already computed and
// the mutex is cleared, so we need to re-check the value again
final T t = (T) UNSAFE.getReferenceAcquire(array, offset);
if (t != null) {
return t;
}
throwIfPreviousException(index, throwables, input);
// There must be an exception
throw cannotReachHere(functionHolder, input);