Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Cannot invoke method hashCode() on null object #8303

Closed
duzhanfei opened this issue Nov 23, 2020 · 3 comments

Comments

@duzhanfei
Copy link

Which version of ShardingSphere did you use?

5.0.0

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

shardingProxy

The problem occued in my project when i invoke interface for updating .
and the sharding key is not null. the result is ok when i change the proxy version to 4.1.1

part of proxy config:

pbcst_qry_info:
  actualDataNodes: ms_ds.pbcst_qry_info_${0..15}
  tableStrategy:
    standard:
      shardingColumn: ecif_cust_no
      shardingAlgorithmName: pbcst_qry_info_inline
  databaseStrategy:
    standard:
      shardingColumn: ecif_cust_no
      shardingAlgorithmName: database_inline
  keyGenerateStrategy:
    column: ecif_cust_no
    keyGeneratorName: snowflake

pbcst_qry_info_inline:
type: INLINE
props:
algorithm-expression: pbcst_qry_info_${Math.abs(ecif_cust_no.hashCode() % 16)}

log:
[INFO ] 16:01:20.936 [ShardingSphere-Command-12] ShardingSphere-SQL - Logic SQL: SELECT @@session.transaction_read_only
[INFO ] 16:01:20.937 [ShardingSphere-Command-12] ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty)
[INFO ] 16:01:20.937 [ShardingSphere-Command-12] ShardingSphere-SQL - Actual SQL: replica_ds_0 ::: SELECT @@session.transaction_read_only
[ERROR] 16:01:27.249 [ShardingSphere-Command-13] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.lang.NullPointerException: Cannot invoke method hashCode() on null object
at org.codehaus.groovy.runtime.NullObject.hashCode(NullObject.java:174)
at org.codehaus.groovy.runtime.NullObject$hashCode.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.NullObject$hashCode.call(Unknown Source)
at Script23$_run_closure1.doCall(Script23.groovy:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at groovy.lang.Closure.call(Closure.java:420)
at groovy.lang.Closure.call(Closure.java:414)
at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.doSharding(InlineShardingAlgorithm.java:69)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:67)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:56)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeTables(ShardingStandardRoutingEngine.java:214)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:194)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:114)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:107)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:84)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:69)
at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:70)
at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:55)
at org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:59)
at org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:57)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:52)
at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:77)
at org.apache.shardingsphere.proxy.backend.text.query.QueryBackendHandler.execute(QueryBackendHandler.java:61)
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:62)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:100)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:76)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

@terrymanu
Copy link
Member

terrymanu commented Nov 23, 2020

The inline expression is write by yourself, please make sure it is correct.
For example: Avoid use null value or judge null before call hashcode method

@duzhanfei
Copy link
Author

Thank you for your reply very much ,the sharding column is not null ,I wonder what went wrong.

@duzhanfei
Copy link
Author

the config of config-replica-query.yaml

schemaName: replica_query_db

dataSourceCommon:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
maintenanceIntervalMilliseconds: 30000

dataSources:
primary_ds:
url: jdbc:mysql://127.5.2.31:3306/crm_customer_db_master0?serverTimezone=UTC&useSSL=false
username: root
password: root
replica_ds_0:
url: jdbc:mysql://127.5.2.32:3306/crm_customer_db_master0_slave0?serverTimezone=UTC&useSSL=false
username: root
password: root
replica_ds_1:
url: jdbc:mysql://127.5.2.33:3306/crm_customer_db_master0_slave1?serverTimezone=UTC&useSSL=false
username: root
password: root
ds_default:
url: jdbc:mysql://127.5.2.34:3306/cdsp_crm_db?serverTimezone=UTC&useSSL=false
username: root
password: root

rules:

  • !SHARDING
    tables:
    pbcst_qry_info:
    actualDataNodes: ms_ds.pbcst_qry_info_${0..15}
    tableStrategy:
    standard:
    shardingColumn: ecif_cust_no
    shardingAlgorithmName: pbcst_qry_info_inline
    databaseStrategy:
    standard:
    shardingColumn: ecif_cust_no
    shardingAlgorithmName: database_inline
    keyGenerateStrategy:
    column: ecif_cust_no
    keyGeneratorName: snowflake

    defaultDatabaseStrategy:
    standard:
    shardingColumn: ecif_cust_no
    shardingAlgorithmName: ds_default
    defaultTableStrategy:
    none:

    shardingAlgorithms:
    database_default_inline:
    type: INLINE
    props:
    algorithm-expression: ms_ds
    database_inline:
    type: INLINE
    props:
    algorithm-expression: ms_ds
    pbcst_qry_info_inline:
    type: INLINE
    props:
    algorithm-expression: pbcst_qry_info_${Math.abs(ecif_cust_no.hashCode() % 16)}

    keyGenerators:
    snowflake:
    type: SNOWFLAKE
    props:
    worker-id: 123

  • !REPLICA_QUERY
    dataSources:
    ms_ds:
    name: ms_ds
    primaryDataSourceName: primary_ds
    replicaDataSourceNames:
    - replica_ds_0
    - replica_ds_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants