Skip to content

Commit 0c420e0

Browse files
committed
8287430: MemorySessionImpl::addOrCleanupIfFail does not rethrow exceptions
Reviewed-by: jvernee
1 parent 1606d55 commit 0c420e0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,19 @@ public void addOrCleanupIfFail(ResourceList.ResourceCleanup resource) {
9797
addInternal(resource);
9898
} catch (Throwable ex) {
9999
resource.cleanup();
100+
throw ex;
100101
}
101102
}
102103

103104
void addInternal(ResourceList.ResourceCleanup resource) {
104-
try {
105-
checkValidStateSlow();
106-
resourceList.add(resource);
107-
} catch (ScopedMemoryAccess.ScopedAccessError err) {
108-
throw new IllegalStateException("Already closed");
109-
}
105+
checkValidStateSlow();
106+
// Note: from here on we no longer check the session state. Two cases are possible: either the resource cleanup
107+
// is added to the list when the session is still open, in which case everything works ok; or the resource
108+
// cleanup is added while the session is being closed. In this latter case, what matters is whether we have already
109+
// called `ResourceList::cleanup` to run all the cleanup actions. If not, we can still add this resource
110+
// to the list (and, in case of an add vs. close race, it might happen that the cleanup action will be
111+
// called immediately after).
112+
resourceList.add(resource);
110113
}
111114

112115
protected MemorySessionImpl(Thread owner, ResourceList resourceList, Cleaner cleaner) {

0 commit comments

Comments
 (0)