This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new 5cf9151a [BCEL-376] ClassPath.close() throws 
UnsupportedOperationException when created with system-classpath
5cf9151a is described below

commit 5cf9151a99ca5a123a6ef1157fd3a68842b5da9a
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Feb 7 08:07:03 2025 -0500

    [BCEL-376] ClassPath.close() throws UnsupportedOperationException when
    created with system-classpath
---
 src/changes/changes.xml                                     | 1 +
 src/main/java/org/apache/bcel/util/ModularRuntimeImage.java | 6 +++++-
 src/test/java/org/apache/bcel/util/ClassPathTestCase.java   | 8 +++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f0ab4698..611e3c6b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -63,6 +63,7 @@ The <action> type attribute can be add,update,fix,remove.
       <!-- FIX -->
       <action                  type="fix" dev="ggregory" due-to="Gary 
Gregory">Replace internal use of Locale.ENGLISH with Locale.ROOT.</action>
       <action issue="BCEL-375" type="fix" dev="ggregory" due-to="J. Lewis 
Muir, Gary Gregory">Wrong permissions on bcel .jar file in binary .tar.gz 
distribution file.</action>
+      <action issue="BCEL-376" type="fix" dev="ggregory" due-to="Dominik 
Stadler, Gary Gregory">ClassPath.close() throws UnsupportedOperationException 
when created with system-classpath.</action>
       <!-- ADD -->
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Add Const.MAJOR_25.</action>
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Add Const.MINOR_25.</action>
diff --git a/src/main/java/org/apache/bcel/util/ModularRuntimeImage.java 
b/src/main/java/org/apache/bcel/util/ModularRuntimeImage.java
index d39b71fd..90015615 100644
--- a/src/main/java/org/apache/bcel/util/ModularRuntimeImage.java
+++ b/src/main/java/org/apache/bcel/util/ModularRuntimeImage.java
@@ -81,7 +81,11 @@ public class ModularRuntimeImage implements Closeable {
             classLoader.close();
         }
         if (fileSystem != null) {
-            fileSystem.close();
+            try {
+                fileSystem.close();
+            } catch (final UnsupportedOperationException e) {
+                // do nothing
+            }
         }
     }
 
diff --git a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java 
b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
index 7fb1d0b9..b69599d5 100644
--- a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
+++ b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.bcel.util;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -29,6 +28,13 @@ import org.junit.jupiter.api.Test;
 
 public class ClassPathTestCase extends AbstractTestCase {
 
+    @Test
+    void testClose() throws IOException {
+        try (ClassPath cp = new ClassPath(ClassPath.getClassPath())) {
+            assertNotNull(cp);
+        }
+    }
+
     @Test
     public void testGetClassFile() throws IOException {
         
assertNotNull(ClassPath.SYSTEM_CLASS_PATH.getClassFile("java.lang.String"));

Reply via email to