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 2020/05/05 03:43:29 UTC

[GitHub] [shardingsphere] TaoZhiMLND opened a new issue #5422: SQLLogger#logSQL throws an NPE when invoked in ShardingStatement

TaoZhiMLND opened a new issue #5422:
URL: https://github.com/apache/shardingsphere/issues/5422


   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   current master branch - 5.0.0-RC1-SNAPSHOT
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-JDBC
   ### Expected behavior
   sql.show is available 
   ### Actual behavior
   set sql.show true and run test of transaction-2pc-xa-raw-jdbc-example module, an NPE throws out from ShardingStatement.
   ### Reason analyze (If you can)
   When #logSQL execute, ExecutionContext was not init complete yet.
   ```java
       private ExecutionContext createExecutionContext(final String sql) throws SQLException {
           clearStatements();
           RuntimeContext runtimeContext = connection.getRuntimeContext();
           SQLStatement sqlStatement = runtimeContext.getSqlParserEngine().parse(sql, false);
           RouteContext routeContext = new DataNodeRouter(
                   runtimeContext.getMetaData(), runtimeContext.getProperties(), runtimeContext.getRules()).route(sqlStatement, sql, Collections.emptyList());
           SQLRewriteResult sqlRewriteResult = new SQLRewriteEntry(runtimeContext.getMetaData().getSchema().getConfiguredSchemaMetaData(),
                   runtimeContext.getProperties(), runtimeContext.getRules()).rewrite(sql, Collections.emptyList(), routeContext);
           ExecutionContext result = new ExecutionContext(routeContext.getSqlStatementContext(), ExecutionContextBuilder.build(runtimeContext.getMetaData(), sqlRewriteResult));
           logSQL(sql, runtimeContext.getProperties());
           return result;
       }
       
       private void logSQL(final String sql, final ConfigurationProperties properties) {
           if (properties.<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW)) {
               SQLLogger.logSQL(sql, properties.<Boolean>getValue(ConfigurationPropertyKey.SQL_SIMPLE), executionContext);
           }
       }
   ```
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   set sql.show true and run test of transaction-2pc-xa-raw-jdbc-example module
   ### Example codes for reproduce this issue (such as a github link).
   


----------------------------------------------------------------
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.

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