You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by te...@apache.org on 2020/11/27 02:38:43 UTC

[shardingsphere-elasticjob] branch master updated: Add null check in SnapshotService to avoid NPE (#1734)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 81d5b80  Add null check in SnapshotService to avoid NPE (#1734)
81d5b80 is described below

commit 81d5b8016ed270b04767dc9d0ee67b78abc99a02
Author: 吴伟杰 <ro...@me.com>
AuthorDate: Fri Nov 27 10:38:30 2020 +0800

    Add null check in SnapshotService to avoid NPE (#1734)
    
    * Add null check in SnapshotService to avoid NPE
    
    * Modify default value if cacheData not present
---
 .../lite/internal/snapshot/SnapshotService.java           | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/snapshot/SnapshotService.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/snapshot/SnapshotService.java
index 1ce6662..311bfa4 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/snapshot/SnapshotService.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/snapshot/SnapshotService.java
@@ -109,14 +109,15 @@ public final class SnapshotService {
     private void dumpDirectly(final String path, final String jobName, final List<String> result) {
         for (String each : regCenter.getChildrenKeys(path)) {
             String zkPath = path + "/" + each;
-            String zkValue = regCenter.get(zkPath);
-            if (null == zkValue) {
-                zkValue = "";
-            }
+            String zkValue = Optional.ofNullable(regCenter.get(zkPath)).orElse("");
+            String cachePath = zkPath;
+            String cacheValue = zkValue;
             CuratorCache cache = (CuratorCache) regCenter.getRawCache("/" + jobName);
-            Optional<ChildData> cacheData = cache.get(zkPath);
-            String cachePath = cacheData.map(ChildData::getPath).orElse("");
-            String cacheValue = cacheData.map(childData -> new String(childData.getData())).orElse("");
+            if (null != cache) {
+                Optional<ChildData> cacheData = cache.get(zkPath);
+                cachePath = cacheData.map(ChildData::getPath).orElse("");
+                cacheValue = cacheData.map(ChildData::getData).map(String::new).orElse("");
+            }
             if (zkValue.equals(cacheValue) && zkPath.equals(cachePath)) {
                 result.add(String.join(" | ", zkPath, zkValue));
             } else {