linghengqian commented on code in PR #30139:
URL: https://github.com/apache/shardingsphere/pull/30139#discussion_r1492259553
##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/url/type/ClassPathURLLoader.java:
##########
@@ -35,16 +36,12 @@ public final class ClassPathURLLoader implements
ShardingSphereURLLoader {
@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final ShardingSphereURL url) {
- try (InputStream inputStream =
getResourceAsStreamFromClasspath(url.getConfigurationSubject())) {
- return ConfigurationContentReader.read(inputStream,
URLArgumentPlaceholderTypeFactory.valueOf(url.getParameters()));
- }
+ return
ConfigurationContentReader.read(getResourceFile(url.getConfigurationSubject()),
URLArgumentPlaceholderTypeFactory.valueOf(url.getParameters()));
}
- private InputStream getResourceAsStreamFromClasspath(final String
resource) {
- InputStream result =
Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
- result = null == result ?
Thread.currentThread().getContextClassLoader().getResourceAsStream("/" +
resource) : result;
- Preconditions.checkNotNull(result, "Can not find configuration file
`%s`.", resource);
- return result;
+ @SneakyThrows(URISyntaxException.class)
+ private File getResourceFile(final String configurationSubject) {
+ return new
File(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(configurationSubject)).toURI().getPath());
Review Comment:
- Is it possible to avoid creating a `java.nio.file.File` instance by
returning a `java.nio.file.Path` instance directly? Creating a
`java.nio.file.File` instance under GraalVM Native Image will cause it to get
the wrong `java.nio.file.Path`, thus breaking GraalVM Native Image integration.
Reference #29014 and #29009.
```shell
Caused by: java.nio.file.NoSuchFileException:
/test-native/yaml/modes/cluster/zookeeper.yaml
at
[email protected]/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at
[email protected]/java.nio.file.Files.newByteChannel(Files.java:379)
at
[email protected]/java.nio.file.Files.newByteChannel(Files.java:431)
at
[email protected]/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at
[email protected]/java.nio.file.Files.newInputStream(Files.java:159)
at
[email protected]/java.nio.file.Files.newBufferedReader(Files.java:2897)
at [email protected]/java.nio.file.Files.readAllLines(Files.java:3392)
at [email protected]/java.nio.file.Files.readAllLines(Files.java:3433)
at
org.apache.shardingsphere.driver.jdbc.core.driver.url.type.ClassPathURLLoader.load(ClassPathURLLoader.java:39)
at
org.apache.shardingsphere.driver.jdbc.core.driver.url.ShardingSphereURLLoadEngine.loadContent(ShardingSphereURLLoadEngine.java:47)
at
org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:55)
... 77 common frames omitted
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]