From 0ea7575cdf3f728fa1693967d2c056596bbebf3b Mon Sep 17 00:00:00 2001 From: Dmitry Kryukov Date: Wed, 10 Jul 2024 21:26:50 +0300 Subject: [PATCH] BugFix Implemented try-with-resources for URLClassLoader in the class FinalizableReferenceQueue --- .../com/google/common/base/FinalizableReferenceQueue.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guava/src/com/google/common/base/FinalizableReferenceQueue.java b/guava/src/com/google/common/base/FinalizableReferenceQueue.java index 7f1afbb3904d..1c0fc45e62f1 100644 --- a/guava/src/com/google/common/base/FinalizableReferenceQueue.java +++ b/guava/src/com/google/common/base/FinalizableReferenceQueue.java @@ -295,8 +295,9 @@ public Class loadFinalizer() { * * System class loader will (and must) be the parent. */ - ClassLoader finalizerLoader = newLoader(getBaseUrl()); - return finalizerLoader.loadClass(FINALIZER_CLASS_NAME); + try (URLClassLoader finalizerLoader = newLoader(getBaseUrl())) { + return finalizerLoader.loadClass(FINALIZER_CLASS_NAME); + } } catch (Exception e) { logger.log(Level.WARNING, LOADING_ERROR, e); return null;