This is an automated email from the ASF dual-hosted git repository.

tuichenchuxin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 743070b5632 Fix NPE occurred when transaction management is not 
created(#21013) (#21091)
743070b5632 is described below

commit 743070b563229705819078196679e291e02ec157
Author: ZhangCheng <[email protected]>
AuthorDate: Wed Sep 21 16:29:55 2022 +0800

    Fix NPE occurred when transaction management is not created(#21013) (#21091)
    
    * Fix NPE occurred when transaction management is not created(#21013)
    
    * Fix NPE occurred when transaction management is not created(#21013)
    
    * Add log
    
    * Modify log level
---
 .../org/apache/shardingsphere/transaction/rule/TransactionRule.java   | 4 ++++
 .../transaction/xa/XAShardingSphereTransactionManager.java            | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
 
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
index d1e542c51be..580221154a8 100644
--- 
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
+++ 
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
@@ -57,6 +57,7 @@ public final class TransactionRule implements GlobalRule, 
ResourceHeldRule<Shard
     private volatile ShardingSphereTransactionManagerEngine resource;
     
     public TransactionRule(final TransactionRuleConfiguration ruleConfig, 
final Map<String, ShardingSphereDatabase> databases, final InstanceContext 
instanceContext) {
+        log.debug("Create transaction rule");
         configuration = ruleConfig;
         defaultType = 
TransactionType.valueOf(ruleConfig.getDefaultType().toUpperCase());
         providerType = ruleConfig.getProviderType();
@@ -95,6 +96,7 @@ public final class TransactionRule implements GlobalRule, 
ResourceHeldRule<Shard
         if (null == database) {
             return;
         }
+        log.debug("Transaction rule add resource: {}", database.getName());
         rebuildEngine();
     }
     
@@ -103,11 +105,13 @@ public final class TransactionRule implements GlobalRule, 
ResourceHeldRule<Shard
         if (!databases.containsKey(databaseName.toLowerCase())) {
             return;
         }
+        log.debug("Transaction rule close resource: {}", databaseName);
         rebuildEngine();
     }
     
     @Override
     public synchronized void closeStaleResource() {
+        log.debug("Transaction rule close all resources");
         closeEngine();
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
 
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
index 61153058a03..c09471c78c1 100644
--- 
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
+++ 
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
@@ -70,7 +70,7 @@ public final class XAShardingSphereTransactionManager 
implements ShardingSphereT
     @SneakyThrows(SystemException.class)
     @Override
     public boolean isInTransaction() {
-        return Status.STATUS_NO_TRANSACTION != 
xaTransactionManagerProvider.getTransactionManager().getStatus();
+        return xaTransactionManagerProvider != null && 
Status.STATUS_NO_TRANSACTION != 
xaTransactionManagerProvider.getTransactionManager().getStatus();
     }
     
     @Override

Reply via email to