This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 8a18305ae60 Prevent ClasspathResourceDirectoryReader from accessing
closed NativeImageResourceFileSystem (#30346)
8a18305ae60 is described below
commit 8a18305ae60c7988b2352a73744d0a6ffe43a751
Author: Ling Hengqian <[email protected]>
AuthorDate: Thu Feb 29 19:28:43 2024 +0800
Prevent ClasspathResourceDirectoryReader from accessing closed
NativeImageResourceFileSystem (#30346)
* Prevent ClasspathResourceDirectoryReader from accessing closed
NativeImageResourceFileSystem
* Prevent automatic closing of NativeImageResourceFileSystem
* Removes redundant FileSystem decisions
---
.../reflect-config.json | 67 +++++++++++++---------
.../resource-config.json | 2 +-
.../ClasspathResourceDirectoryReader.java | 23 +++++---
3 files changed, 57 insertions(+), 35 deletions(-)
diff --git
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json
index d2dbe70ffa6..7490dab5380 100644
---
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json
+++
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json
@@ -188,6 +188,46 @@
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"},
"name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationCustomizer"
},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"},
+
"name":"org.apache.shardingsphere.infra.algorithm.keygen.snowflake.SnowflakeKeyGenerateAlgorithm",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"},
+
"name":"org.apache.shardingsphere.infra.algorithm.keygen.uuid.UUIDKeyGenerateAlgorithm",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
+
"name":"org.apache.shardingsphere.infra.algorithm.load.balancer.random.RandomLoadBalanceAlgorithm",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
+
"name":"org.apache.shardingsphere.infra.algorithm.load.balancer.round.robin.RoundRobinLoadBalanceAlgorithm",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
+
"name":"org.apache.shardingsphere.infra.algorithm.load.balancer.weight.WeightLoadBalanceAlgorithm",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory"},
+
"name":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory"},
+
"name":"org.apache.shardingsphere.infra.expr.interval.IntervalInlineExpressionParser",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
+{
+
"condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory"},
+
"name":"org.apache.shardingsphere.infra.expr.literal.LiteralInlineExpressionParser",
+ "methods":[{"name":"<init>","parameterTypes":[] }]
+},
{
"condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService"},
"name":"org.apache.shardingsphere.infra.instance.ComputeNodeData",
@@ -203,16 +243,6 @@
"condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService"},
"name":"org.apache.shardingsphere.infra.instance.ComputeNodeDataCustomizer"
},
-{
-
"condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"},
-
"name":"org.apache.shardingsphere.infra.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm",
- "methods":[{"name":"<init>","parameterTypes":[] }]
-},
-{
-
"condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"},
-
"name":"org.apache.shardingsphere.infra.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm",
- "methods":[{"name":"<init>","parameterTypes":[] }]
-},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheBuilder"},
"name":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader"
@@ -545,7 +575,7 @@
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
-
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader$2"},
+
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
"name":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQL",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
@@ -597,21 +627,6 @@
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"},
"name":"org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfigurationCustomizer"
},
-{
-
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
-
"name":"org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReadQueryLoadBalanceAlgorithm",
- "methods":[{"name":"<init>","parameterTypes":[] }]
-},
-{
-
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
-
"name":"org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RoundRobinReadQueryLoadBalanceAlgorithm",
- "methods":[{"name":"<init>","parameterTypes":[] }]
-},
-{
-
"condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule"},
-
"name":"org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightReadQueryLoadBalanceAlgorithm",
- "methods":[{"name":"<init>","parameterTypes":[] }]
-},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"},
"name":"org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration",
diff --git
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json
index 2ca0e73753f..fa5be0653ed 100644
---
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json
+++
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json
@@ -13,7 +13,7 @@
"condition":{"typeReachable":"org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager"},
"pattern":"\\QMETA-INF/services/java.sql.Driver\\E"
}, {
-
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
+
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.directory.ClasspathResourceDirectoryReader"},
"pattern":"\\Qsql\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"},
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 14c64f9695a..acf327c1ea5 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
@@ -22,11 +22,11 @@ import lombok.SneakyThrows;
import java.io.IOException;
import java.net.JarURLConnection;
-import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.FileSystem;
+import java.nio.file.FileSystemNotFoundException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
@@ -66,7 +66,7 @@ public class ClasspathResourceDirectoryReader {
* @param name resource name
* @return true if the resource is a directory; false if the resource does
not exist, is not a directory, or it cannot be determined if the resource is a
directory or not.
*/
- @SneakyThrows({IOException.class, URISyntaxException.class})
+ @SneakyThrows(URISyntaxException.class)
public static boolean isDirectory(final ClassLoader classLoader, final
String name) {
URL resourceUrl = classLoader.getResource(name);
if (null == resourceUrl) {
@@ -79,11 +79,6 @@ public class ClasspathResourceDirectoryReader {
}
return jarFile.getJarEntry(name).isDirectory();
} else {
- if ("resourceUrl".equals(resourceUrl.getProtocol())) {
- try (FileSystem ignored =
FileSystems.newFileSystem(URI.create("resource:/"), Collections.emptyMap())) {
- return Files.isDirectory(Paths.get(resourceUrl.toURI()));
- }
- }
return Files.isDirectory(Paths.get(resourceUrl.toURI()));
}
}
@@ -162,6 +157,9 @@ public class ClasspathResourceDirectoryReader {
* This is mainly to align the behavior of `jdk.nio.zipfs.ZipFileSystem`,
* so ShardingSphere need to manually open and close the FileSystem
corresponding to the `resource:/` scheme.
* For more background reference <a
href="https://github.com/oracle/graal/issues/7682">oracle/graal#7682</a>.
+ * Under the context of third-party dependencies such as Spring Framework
OSS,
+ * `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem` will
be automatically created during the life cycle of the context,
+ * so additional determination is required.
*
* @param directoryUrl directory url
* @return stream of resource name
@@ -169,8 +167,17 @@ public class ClasspathResourceDirectoryReader {
@SneakyThrows({IOException.class, URISyntaxException.class})
private static Stream<String> readDirectoryInFileSystem(final URL
directoryUrl) {
if ("resource".equals(directoryUrl.getProtocol())) {
- try (FileSystem ignored =
FileSystems.newFileSystem(URI.create("resource:/"), Collections.emptyMap())) {
+ try {
return loadFromDirectory(directoryUrl);
+ } catch (FileSystemNotFoundException exception) {
+ FileSystem nativeImageResourceFileSystem =
FileSystems.newFileSystem(directoryUrl.toURI(), Collections.emptyMap());
+ return loadFromDirectory(directoryUrl).onClose(() -> {
+ try {
+ nativeImageResourceFileSystem.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
}
}
return loadFromDirectory(directoryUrl);