OSDN Git Service

avoid NPE with noconf mode.
authorOlyutorskii <olyutorskii@users.osdn.me>
Wed, 13 May 2020 17:36:46 +0000 (02:36 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Wed, 13 May 2020 17:36:46 +0000 (02:36 +0900)
src/main/java/jp/sfjp/jindolf/config/JsonIo.java

index 2fba756..415b97c 100644 (file)
@@ -81,6 +81,10 @@ public class JsonIo {
      *     もしくは入力エラーがあればnull
      */
     public JsObject loadJsObject(Path file){
+        if( ! this.configStore.useStoreFile()){
+            return null;
+        }
+
         JsComposition<?> root = loadJson(file);
         if(root == null || root.getJsTypes() != JsTypes.OBJECT) return null;
         JsObject result = (JsObject) root;
@@ -96,7 +100,7 @@ public class JsonIo {
      *     もしくはJSONファイルが存在しない、
      *     もしくは入力エラーがあればnull
      */
-    public JsComposition<?> loadJson(Path file){
+    protected JsComposition<?> loadJson(Path file){
         Path absFile;
         if(file.isAbsolute()){
             absFile = file;
@@ -171,6 +175,10 @@ public class JsonIo {
      *     何らかの理由でセーブが完了できなければfalse
      */
     public boolean saveJson(Path file, JsComposition<?> root){
+        if( ! this.configStore.useStoreFile()){
+            return false;
+        }
+
         // TODO テンポラリファイルを用いたより安全なファイル更新
         Path configDir = this.configStore.getConfigDir();
         Path absFile = configDir.resolve(file);