Skip to content

Commit

Permalink
Adjust how we close the CL and throw an exception when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jul 7, 2024
1 parent d00b246 commit 7dcb1d4
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ public void close() {
log.debug("Failed to clean up DB drivers");
}
}

status = STATUS_CLOSED;

closeClassPathElements(elements);
closeClassPathElements(bannedElements);
closeClassPathElements(parentFirstElements);
Expand All @@ -707,8 +710,6 @@ public void close() {
classLoaderEventListeners.clear();

ResourceBundle.clearCache(this);

status = STATUS_CLOSED;
}

private static void closeClassPathElements(List<ClassPathElement> classPathElements) {
Expand All @@ -730,11 +731,17 @@ public boolean isClosed() {
}

private void ensureOpen() {
if (LOG_ACCESS_TO_CLOSED_CLASS_LOADERS && status == STATUS_CLOSED) {
if (status != STATUS_CLOSED) {
return;
}

if (LOG_ACCESS_TO_CLOSED_CLASS_LOADERS) {
// we do not use a logger as it might require some class loading
System.out.println("Class loader " + this + " has been closed and may not be accessed anymore");
Thread.dumpStack();
}

throw new IllegalStateException("Class loader " + this + " has been closed and may not be accessed anymore");
}

@Override
Expand Down

0 comments on commit 7dcb1d4

Please sign in to comment.