}
finally {
writeLock.unlock();
}
}
if ( indexReader.tryIncRef() ) {
return indexReader;
}
else {
//In this case we have a race: the chosen IndexReader was closed before we could increment its reference, so we need
//to try again. Basically an optimistic lock as the race condition is very unlikely.