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 2021/08/03 05:43:24 UTC

[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1952: Fix NPE in InstanceService.getAvailableJobInstances

TeslaCN commented on a change in pull request #1952:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1952#discussion_r681450706



##########
File path: elasticjob-infra/elasticjob-registry-center/src/main/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenter.java
##########
@@ -137,10 +137,7 @@ public String get(final String key) {
             return getDirectly(key);
         }
         Optional<ChildData> resultInCache = cache.get(key);
-        if (resultInCache.isPresent()) {
-            return null == resultInCache.get().getData() ? null : new String(resultInCache.get().getData(), StandardCharsets.UTF_8);
-        }
-        return getDirectly(key);
+        return resultInCache.map(v -> null == v.getData() ? null : new String(v.getData(), StandardCharsets.UTF_8)).orElse(getDirectly(key));

Review comment:
       Use `orElseGet` to avoid invoking `getDirectly` every time.




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