8287430: MemorySessionImpl::addOrCleanupIfFail does not rethrow exceptions

Reviewed-by: jvernee
This commit is contained in:
Maurizio Cimadamore 2022-05-30 15:40:06 +00:00
parent 1606d5545b
commit 0c420e03ae

@ -97,16 +97,19 @@ public abstract non-sealed class MemorySessionImpl implements Scoped, MemorySess
addInternal(resource);
} catch (Throwable ex) {
resource.cleanup();
throw ex;
}
}
void addInternal(ResourceList.ResourceCleanup resource) {
try {
checkValidStateSlow();
resourceList.add(resource);
} catch (ScopedMemoryAccess.ScopedAccessError err) {
throw new IllegalStateException("Already closed");
}
checkValidStateSlow();
// Note: from here on we no longer check the session state. Two cases are possible: either the resource cleanup
// is added to the list when the session is still open, in which case everything works ok; or the resource
// cleanup is added while the session is being closed. In this latter case, what matters is whether we have already
// called `ResourceList::cleanup` to run all the cleanup actions. If not, we can still add this resource
// to the list (and, in case of an add vs. close race, it might happen that the cleanup action will be
// called immediately after).
resourceList.add(resource);
}
protected MemorySessionImpl(Thread owner, ResourceList resourceList, Cleaner cleaner) {