You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/04/14 11:10:45 UTC
[GitHub] [shardingsphere] jinkun2014 opened a new issue, #16831: NullPointException possibly caused by org.apache.shardingsphere.sharding.rule.ShardingRule#createBindingTableRules
jinkun2014 opened a new issue, #16831:
URL: https://github.com/apache/shardingsphere/issues/16831
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
5.1.0
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
### Expected behavior
### Actual behavior
```
Caused by: java.lang.NullPointerException: null
at org.apache.shardingsphere.sharding.rule.ShardingRule.isBroadcastTable(ShardingRule.java:375)
at org.apache.shardingsphere.sharding.rule.ShardingRule.getTableRule(ShardingRule.java:270)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.apache.shardingsphere.sharding.rule.ShardingRule.createBindingTableRule(ShardingRule.java:201)
at org.apache.shardingsphere.sharding.rule.ShardingRule.createBindingTableRules(ShardingRule.java:191)
at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:128)
at org.apache.shardingsphere.sharding.rule.builder.AlgorithmProvidedShardingRuleBuilder.build(AlgorithmProvidedShardingRuleBuilder.java:41)
at org.apache.shardingsphere.sharding.rule.builder.AlgorithmProvidedShardingRuleBuilder.build(AlgorithmProvidedShardingRuleBuilder.java:35)
at org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder.buildRules(SchemaRulesBuilder.java:63)
at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.getSchemaRules(MetaDataContextsBuilder.java:85)
at org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder.addSchema(MetaDataContextsBuilder.java:77)
at org.apache.shardingsphere.mode.manager.memory.MemoryContextManagerBuilder.build(MemoryContextManagerBuilder.java:47)
at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:81)
at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:77)
at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration.shardingSphereDataSource(ShardingSphereAutoConfiguration.java:93)
at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$EnhancerBySpringCGLIB$$5d9b62a.CGLIB$shardingSphereDataSource$2(<generated>)
at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$EnhancerBySpringCGLIB$$5d9b62a$$FastClassBySpringCGLIB$$de6581a8.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration$$EnhancerBySpringCGLIB$$5d9b62a.shardingSphereDataSource(<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)
... 73 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:54983', transport: 'socket'
Process finished with exit code 1
```
### Reason analyze (If you can)
```
public ShardingRule(final ShardingRuleConfiguration config, final Collection<String> dataSourceNames) {
...
bindingTableRules.putAll(createBindingTableRules(config.getBindingTableGroups()));
broadcastTables = createBroadcastTables(config.getBroadcastTables());
....
}
private Map<String, BindingTableRule> createBindingTableRules(final Collection<String> bindingTableGroups) {
....
BindingTableRule bindingTableRule = createBindingTableRule(each);
...
return result;
}
private BindingTableRule createBindingTableRule(final String bindingTableGroup) {
Map<String, TableRule> tableRules = Splitter.on(",").trimResults().splitToList(bindingTableGroup).stream()
.map(this::getTableRule).collect(Collectors.toMap(each -> each.getLogicTable().toLowerCase(), Function.identity(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
....
}
// if the method findTableRule return null it will call isBroadcastTable()
public TableRule getTableRule(final String logicTableName) {
Optional<TableRule> tableRule = findTableRule(logicTableName);
if (tableRule.isPresent()) {
return tableRule.get();
}
if (isBroadcastTable(logicTableName)) {
return new TableRule(dataSourceNames, logicTableName);
}
throw new ShardingSphereConfigurationException("Cannot find table rule with logic table: '%s'", logicTableName);
}
// but broadcastTables is null , because it has not been initialized
public boolean isBroadcastTable(final String logicTableName) {
return broadcastTables.contains(logicTableName);
}
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
```
spring:
shardingsphere:
rules:
sharding:
tables:
oms_order:
actual-data-nodes: ds$->{0..1}.oms_order
binding-tables:
- oms_order,t_address
broadcast-tables:
- t_address
```
### Example codes for reproduce this issue (such as a github link).
Adjust initialization order ?
```
broadcastTables = createBroadcastTables(config.getBroadcastTables());
bindingTableRules.putAll(createBindingTableRules(config.getBindingTableGroups()));
```
--
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
[GitHub] [shardingsphere] strongduanmu closed issue #16831: NullPointException possibly caused by org.apache.shardingsphere.sharding.rule.ShardingRule#createBindingTableRules
Posted by GitBox <gi...@apache.org>.
strongduanmu closed issue #16831: NullPointException possibly caused by org.apache.shardingsphere.sharding.rule.ShardingRule#createBindingTableRules
URL: https://github.com/apache/shardingsphere/issues/16831
--
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] RaigorJiang commented on issue #16831: NullPointException possibly caused by org.apache.shardingsphere.sharding.rule.ShardingRule#createBindingTableRules
Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #16831:
URL: https://github.com/apache/shardingsphere/issues/16831#issuecomment-1100903636
Hi @jinkun2014 ,
Thanks for your feedback, would you like to submit a PR to fix this issue?
--
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