From 80088dd4c8f5afd9e3eee546cbe7332c812e23e8 Mon Sep 17 00:00:00 2001 From: m1504 Date: Sat, 14 Dec 2024 17:44:19 +0800 Subject: [PATCH] fix empty bug. --- src/main/java/com/laosun/stackone/IgnoreItem.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/laosun/stackone/IgnoreItem.java b/src/main/java/com/laosun/stackone/IgnoreItem.java index a41d720..de64e56 100644 --- a/src/main/java/com/laosun/stackone/IgnoreItem.java +++ b/src/main/java/com/laosun/stackone/IgnoreItem.java @@ -29,10 +29,11 @@ public static ArrayList getIgnoreItems() { try { if (!file.exists() && !file.createNewFile()) { LOGGER.info("Fail to create config file."); - } else { - Files.writeString(file.toPath(), "[]", StandardCharsets.UTF_8); } String jsonString = Files.readString(file.toPath()); + if (jsonString.isEmpty()) { + Files.writeString(file.toPath(), "[]", StandardCharsets.UTF_8); + } JsonArray jsonArray = JsonParser.parseString(jsonString).getAsJsonArray(); for (JsonElement user : jsonArray) { IgnoreItem ignore = gson.fromJson(user, IgnoreItem.class);