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-unsubscr...@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to