diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java index 016dbdd191b44b..d736258f2fbd70 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java @@ -692,17 +692,27 @@ public void close() { log.debug("Failed to clean up DB drivers"); } } - for (ClassPathElement element : elements) { - //note that this is a 'soft' close - //all resources are closed, however the CL can still be used - //but after close no resources will be held past the scope of an operation - try (ClassPathElement ignored = element) { - //the close() operation is implied by the try-with syntax - } catch (Exception e) { - log.error("Failed to close " + element, e); - } + closeClassPathElements(elements); + closeClassPathElements(bannedElements); + closeClassPathElements(parentFirstElements); + closeClassPathElements(lesserPriorityElements); + + definedPackages.clear(); + resettableElement = null; + transformedClasses = null; + if (state != null) { + state.clear(); } - for (ClassPathElement element : bannedElements) { + closeTasks.clear(); + classLoaderEventListeners.clear(); + + ResourceBundle.clearCache(this); + + status = STATUS_CLOSED; + } + + private static void closeClassPathElements(List classPathElements) { + for (ClassPathElement element : classPathElements) { //note that this is a 'soft' close //all resources are closed, however the CL can still be used //but after close no resources will be held past the scope of an operation @@ -712,9 +722,7 @@ public void close() { log.error("Failed to close " + element, e); } } - ResourceBundle.clearCache(this); - - status = STATUS_CLOSED; + classPathElements.clear(); } public boolean isClosed() { @@ -900,6 +908,11 @@ static final class ClassLoaderState { this.bannedResources = bannedResources; this.parentFirstResources = parentFirstResources; } + + void clear() { + // when the CL is closed, we make sure the resources are not loadable anymore + loadableResources.clear(); + } } @Override