You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "shiliang-star (via GitHub)" <gi...@apache.org> on 2025/06/25 14:55:55 UTC
[I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
shiliang-star opened a new issue, #28227:
URL: https://github.com/apache/shardingsphere/issues/28227
### Which version of ShardingSphere did you use?
5.4.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
system start successfully
### Actual behavior
system start failed because NPE
> Caused by: java.lang.NullPointerException: null
at org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository.init(JDBCRepository.java:61)
at org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader.findService(TypedSPILoader.java:86)
at org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader.findService(TypedSPILoader.java:70)
at org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader.getService(TypedSPILoader.java:127)
at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:47)
at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:82)
at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:69)
at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:95)
at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:154)
at kl.nbase.db.support.slot.SwitchableDataSourceBuilder.buildDataSource(SwitchableDataSourceBuilder.java:150)
at kl.nbase.db.support.slot.SwitchableDataSourceBuilder.buildSwitchDataSource(SwitchableDataSourceBuilder.java:107)
at kl.nbase.db.support.slot.SwitchableDataSourceBuilder.build(SwitchableDataSourceBuilder.java:45)
at kl.nbase.db.support.spring.DBAutoConfiguration.dataSource(DBAutoConfiguration.java:39)
at kl.nbase.db.support.spring.DBAutoConfiguration$$EnhancerBySpringCGLIB$$cf5811f7.CGLIB$dataSource$0(<generated>)
at kl.nbase.db.support.spring.DBAutoConfiguration$$EnhancerBySpringCGLIB$$cf5811f7$$FastClassBySpringCGLIB$$7785c6d5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at kl.nbase.db.support.spring.DBAutoConfiguration$$EnhancerBySpringCGLIB$$cf5811f7.dataSource(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 67 common frames omitted
### Reason analyze (If you can)
private static final String ROOT_DIRECTORY = "sql";
private static final String FILE_EXTENSION = ".xml";
private static final Collection<String> JAR_URL_PROTOCOLS = new HashSet<>(Arrays.asList("jar", "war", "zip", "wsjar", "vfszip"));
/**
* Load JDBC repository SQL.
*
* @param type type of JDBC repository SQL
* @return loaded JDBC repository SQL
*/
@SneakyThrows({JAXBException.class, IOException.class, URISyntaxException.class})
public static JDBCRepositorySQL load(final String type) {
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(ROOT_DIRECTORY);
if (null == resources) {
return null;
}
JDBCRepositorySQL result = null;
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
result = JAR_URL_PROTOCOLS.contains(resource.getProtocol()) ? loadFromJar(resource, type) : loadFromDirectory(resource, type);
if (null != result && Objects.equals(result.isDefault(), false)) {
break;
}
}
return result;
}
Code from org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader#load
> You have some problems loading sql resources here, because there is a custom name “sql” directory under my classpath, which is also loaded by you. I know that you should load H2.XML. Cyclic loading of the sql directory customized by my class path causes the result object to be NULL, so a null pointer is generated at startup. I don’t know why you have to judge this way here:
if (null != result && Objects.equals(result.isDefault(), false)) can jump out of the loop, I hope to get your explanation, the temporary solution I am doing now is to modify the name of the sql directory under my class path, make it not be loaded here
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-3047850013
- Then again, since https://github.com/apache/shardingsphere/pull/35918 changed `org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository#isDefault()` from `true` to `false`, it seems meaningless to keep this issue open. Because we are discussing an optional module. It is OK for optional modules to do anything.
--
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
[GitHub] [shardingsphere] github-actions[bot] commented on issue #28227: JDBCRepositorySQLLoader load NPE when use H2
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-1732399389
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
--
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: [I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-3005100533
As a review of https://github.com/apache/shardingsphere/issues/26041 and the spring boot 4 snapshot version, I think it is necessary to use spi instead of xml. Because jackson 3 is about to increase the minimum jdk runtime version to jdk17, and shardingsphere currently parses xml through the jackson xml module, which will further cause confusion related to spring boot 4.
--
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: [I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian closed issue #28227: JDBCRepositorySQLLoader load NPE when use H2
URL: https://github.com/apache/shardingsphere/issues/28227
--
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: [I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #28227: JDBCRepositorySQLLoader load NPE when use H2
URL: https://github.com/apache/shardingsphere/issues/28227
--
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
[GitHub] [shardingsphere] zhaojinchao95 commented on issue #28227: JDBCRepositorySQLLoader load NPE when use H2
Posted by "zhaojinchao95 (via GitHub)" <gi...@apache.org>.
zhaojinchao95 commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-1689434948
@shiliang-star Hi, are you interested in fixing it? Avoiding NPE.
--
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
[GitHub] [shardingsphere] shiliang-star commented on issue #28227: JDBCRepositorySQLLoader load NPE when use H2
Posted by "shiliang-star (via GitHub)" <gi...@apache.org>.
shiliang-star commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-1691331865
@terrymanu Can you give me a professional explanation or is there a better way to fix this issue in version 5.4.0
--
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: [I] JDBCRepositorySQLLoader load NPE when use H2 [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #28227:
URL: https://github.com/apache/shardingsphere/issues/28227#issuecomment-2022254407
@shiliang-star
- In the master branch, the ClassLoader that reads `/sql/` has been changed from `Thread.currentThread().getContextClassLoader()` to `JDBCRepositorySQLLoader.class.getClassLoader()`. I don’t think this issue will still exist. You need to additionally verify. Reference https://github.com/apache/shardingsphere/blob/master/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java .
--
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