You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "terrymanu (via GitHub)" <gi...@apache.org> on 2024/02/16 03:49:01 UTC
[PR] Refactor ConfigurationContentReader [shardingsphere]
terrymanu opened a new pull request, #30139:
URL: https://github.com/apache/shardingsphere/pull/30139
(no comment)
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor ConfigurationContentReader [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
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 java.base@21.0.2/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:379)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:431)
at java.base@21.0.2/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base@21.0.2/java.nio.file.Files.newInputStream(Files.java:159)
at java.base@21.0.2/java.nio.file.Files.newBufferedReader(Files.java:2897)
at java.base@21.0.2/java.nio.file.Files.readAllLines(Files.java:3392)
at java.base@21.0.2/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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor ConfigurationContentReader [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
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.io.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 java.base@21.0.2/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:379)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:431)
at java.base@21.0.2/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base@21.0.2/java.nio.file.Files.newInputStream(Files.java:159)
at java.base@21.0.2/java.nio.file.Files.newBufferedReader(Files.java:2897)
at java.base@21.0.2/java.nio.file.Files.readAllLines(Files.java:3392)
at java.base@21.0.2/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
```
##########
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.io.File` instance by returning a `java.nio.file.Path` instance directly? Creating a `java.io.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 java.base@21.0.2/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:379)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:431)
at java.base@21.0.2/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base@21.0.2/java.nio.file.Files.newInputStream(Files.java:159)
at java.base@21.0.2/java.nio.file.Files.newBufferedReader(Files.java:2897)
at java.base@21.0.2/java.nio.file.Files.readAllLines(Files.java:3392)
at java.base@21.0.2/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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor ConfigurationContentReader [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on code in PR #30139:
URL: https://github.com/apache/shardingsphere/pull/30139#discussion_r1492386046
##########
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:
- See #30145 .
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor ConfigurationContentReader [shardingsphere]
Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN merged PR #30139:
URL: https://github.com/apache/shardingsphere/pull/30139
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor ConfigurationContentReader [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
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 java.base@21.0.2/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:379)
at java.base@21.0.2/java.nio.file.Files.newByteChannel(Files.java:431)
at java.base@21.0.2/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base@21.0.2/java.nio.file.Files.newInputStream(Files.java:159)
at java.base@21.0.2/java.nio.file.Files.newBufferedReader(Files.java:2897)
at java.base@21.0.2/java.nio.file.Files.readAllLines(Files.java:3392)
at java.base@21.0.2/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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org