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

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d5eacc44076 Catch an exception when accidentally accessing a closed 
JAR file that is being used by the application. (#30986)
d5eacc44076 is described below

commit d5eacc4407647449d9f77d79cc464347760a6144
Author: Cong Hu <[email protected]>
AuthorDate: Tue Apr 23 12:28:27 2024 +0800

    Catch an exception when accidentally accessing a closed JAR file that is 
being used by the application. (#30986)
---
 .../infra/util/directory/ClasspathResourceDirectoryReader.java | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
index 47c575e376a..64aac2ee11d 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.util.directory;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;
 import java.net.JarURLConnection;
@@ -45,6 +46,7 @@ import java.util.stream.Stream;
 /**
  * Classpath resource directory reader.
  */
+@Slf4j
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class ClasspathResourceDirectoryReader {
     
@@ -131,7 +133,13 @@ public class ClasspathResourceDirectoryReader {
         if (null == jar) {
             return Stream.empty();
         }
-        return jar.stream().filter(each -> 
each.getName().startsWith(directory) && 
!each.isDirectory()).map(JarEntry::getName);
+        try {
+            return jar.stream().filter(each -> 
each.getName().startsWith(directory) && 
!each.isDirectory()).map(JarEntry::getName);
+        } catch (final IllegalStateException ex) {
+            // todo Refactor to use JDK API to filter out closed JAR files 
used by application.
+            log.warn("Access jar file error: {}.", directoryUrl.getPath(), ex);
+            return Stream.empty();
+        }
     }
     
     @SneakyThrows(IOException.class)

Reply via email to