From 077abc8699cb5915a888a30d0d3f7c4b4ef88ac3 Mon Sep 17 00:00:00 2001
From: Prashant <prashant.thakre@gmail.com>
Date: Sat, 21 Nov 2026 08:56:09 +0000
Subject: [PATCH] Close extension jars and manifests read by ConfigurationFramework (#1314)

---
 opendj-config/src/main/java/org/forgerock/opendj/config/ConfigurationFramework.java |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/ConfigurationFramework.java b/opendj-config/src/main/java/org/forgerock/opendj/config/ConfigurationFramework.java
index 779a6d1..0c24061 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/ConfigurationFramework.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/ConfigurationFramework.java
@@ -439,6 +439,21 @@
     private void addExtension(final List<File> extensions) throws ConfigException {
         // First add the Jar files to the class loader.
         final List<JarFile> jars = new LinkedList<>();
+        try {
+            addExtension(extensions, jars);
+        } finally {
+            // Only read for their manifests: the class loader opens the jars on its own.
+            for (final JarFile jar : jars) {
+                try {
+                    jar.close();
+                } catch (final IOException e) {
+                    debugLogger.trace("Unable to close jar file: " + jar.getName(), e);
+                }
+            }
+        }
+    }
+
+    private void addExtension(final List<File> extensions, final List<JarFile> jars) throws ConfigException {
         for (final File extension : extensions) {
             if (jarFiles.contains(extension)) {
                 // Skip this file as it is already loaded.
@@ -546,8 +561,10 @@
         if (is == null) {
             throw new ConfigException(ERR_ADMIN_CANNOT_FIND_CORE_MANIFEST.get(MANIFEST_ABSOLUTE_PATH));
         }
-        try {
-            loadDefinitionClasses(is);
+        try (InputStream manifest = is) {
+            loadDefinitionClasses(manifest);
+        } catch (final IOException e) {
+            debugLogger.trace("Unable to close the core manifest", e);
         } catch (final ConfigException e) {
             debugLogger.trace("Unable to initialize core components", e);
             throw new ConfigException(ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(
@@ -580,8 +597,10 @@
                 throw new ConfigException(message);
             }
 
-            try {
-                loadDefinitionClasses(is);
+            try (InputStream manifest = is) {
+                loadDefinitionClasses(manifest);
+            } catch (final IOException e) {
+                debugLogger.trace("Unable to close the extension manifest", e);
             } catch (final ConfigException e) {
                 debugLogger.trace("Unable to load classes from input stream", e);
                 final LocalizableMessage message = ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(

--
Gitblit v1.10.0