Skip to content

Commit 32fc878

Browse files
authored
Merge pull request #3219 from adamretter/hotfix/weak-lazy-stripes-concurrency
Fix a concurrency issue in WeakLazyStripes
2 parents 363ed27 + abd1a34 commit 32fc878

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

exist-core/src/main/java/org/exist/util/WeakLazyStripes.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ public S get(final K key) {
229229
private @Nullable WeakValueReference<K, S> getOptimistic(final K key, final Holder<Boolean> written) {
230230
// optimistic read
231231
final long stamp = stripesLock.tryOptimisticRead();
232-
WeakValueReference<K, S> stripeRef = stripes.get(key);
232+
WeakValueReference<K, S> stripeRef;
233+
try {
234+
stripeRef = stripes.get(key);
235+
} catch (final ArrayIndexOutOfBoundsException e) {
236+
// this can occur as we don't hold a lock, we just have a stamp for an optimistic read,
237+
// so `stripes` might be concurrently modified
238+
return null;
239+
}
233240
if (stripeRef == null || stripeRef.get() == null) {
234241
final long writeStamp = stripesLock.tryConvertToWriteLock(stamp);
235242
if (writeStamp != 0l) {

0 commit comments

Comments
 (0)