You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2022/01/05 10:16:48 UTC

[shardingsphere] branch master updated: Fix use standalone mode add resource NPE. (#14545)

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

menghaoran 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 c7f5aad  Fix use standalone mode add resource NPE. (#14545)
c7f5aad is described below

commit c7f5aad1c1bde06e4add280262ff531bca2956b9
Author: zhaojinchao <33...@users.noreply.github.com>
AuthorDate: Wed Jan 5 18:15:50 2022 +0800

    Fix use standalone mode add resource NPE. (#14545)
---
 .../mode/repository/standalone/file/FileRepository.java          | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/s [...]
index ea76206..e20e7c3 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-provider/shardingsphere-standalone-mode-repository-file/src/main/java/org/apache/shardingsphere/mode/repository/standalone/file/FileRepository.java
@@ -67,13 +67,20 @@ public final class FileRepository implements StandalonePersistRepository {
     @Override
     public List<String> getChildrenKeys(final String key) {
         File file = new File(path, key);
-        return file.exists() ? Arrays.stream(file.listFiles()).map(File::getName).collect(Collectors.toList())
+        if (!file.exists()) {
+            return Collections.emptyList();
+        }
+        return null != file.listFiles() ? Arrays.stream(file.listFiles()).map(File::getName).collect(Collectors.toList())
                 : Collections.emptyList();
     }
     
     @Override
     public void persist(final String key, final String value) {
         File file = new File(path, key);
+        if (Strings.isNullOrEmpty(value)) {
+            file.mkdirs();
+            return;
+        }
         if (!file.exists()) {
             file.getParentFile().mkdirs();
         }