From 04ba545aa2ead7191a886b92e3a6e34a91bad683 Mon Sep 17 00:00:00 2001 From: Ivan Volkov <65380341+Ivan8or@users.noreply.github.com> Date: Sun, 13 Dec 2020 09:20:10 -0500 Subject: [PATCH] NullPointer fix for /schematic list (#781) * fixed null pointer * fixed rest of similarly caused null pointers * checkstyle --- .../worldedit/command/SchematicCommands.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index ab247e2b0..037cae63c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -601,9 +601,12 @@ public class SchematicCommands { long totalBytes = 0; File parentDir = new File(dir.getAbsolutePath() + (playerFolder ? File.separator + uuid.toString() : "")); try { - for (File schem : getFiles(parentDir, null, null)) { - if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) { - totalBytes += Files.size(Paths.get(schem.getAbsolutePath())); + List toAddUp = getFiles(parentDir, null, null); + if (toAddUp != null && toAddUp.size() != 0) { + for (File schem : toAddUp) { + if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) { + totalBytes += Files.size(Paths.get(schem.getAbsolutePath())); + } } } } catch (IOException e) { @@ -736,15 +739,15 @@ public class SchematicCommands { int numFiles = -1; if (checkFilesize) { - File parentDir = new File(file.getParent()); - - for (File child : getFiles(rootDir, null, null)) { - if (child.getName().endsWith(".schem") || child.getName().endsWith(".schematic")) { - directorysizeKb += Files.size(Paths.get(child.getAbsolutePath())) / 1000.0; - numFiles++; + List toAddUp = getFiles(rootDir, null, null); + if (toAddUp != null && toAddUp.size() != 0) { + for (File child : toAddUp) { + if (child.getName().endsWith(".schem") || child.getName().endsWith(".schematic")) { + directorysizeKb += Files.size(Paths.get(child.getAbsolutePath())) / 1000.0; + numFiles++; + } } } - if (overwrite) { oldKbOverwritten = Files.size(Paths.get(file.getAbsolutePath())) / 1000.0; int iter = 1; @@ -760,9 +763,12 @@ public class SchematicCommands { if (numFiles == -1) { numFiles = 0; - for (File child : getFiles(rootDir, null, null)) { - if (child.getName().endsWith(".schem") || child.getName().endsWith(".schematic")) { - numFiles++; + List toAddUp = getFiles(rootDir, null, null); + if (toAddUp != null && toAddUp.size() != 0) { + for (File child : toAddUp) { + if (child.getName().endsWith(".schem") || child.getName().endsWith(".schematic")) { + numFiles++; + } } } }