From 8988aa82b47b2ad3713d8a005b22c6c1e2791011 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 30 Aug 2018 14:09:24 -0700 Subject: [PATCH] Some alternatives to/for null checking. --- .../getdown/launcher/GetdownApp.java | 4 ++-- .../com/threerings/getdown/util/FileUtil.java | 23 ++++++++----------- .../threerings/getdown/util/LaunchUtil.java | 9 ++------ 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index d25d4cb..8cd431f 100644 --- a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -196,8 +196,8 @@ public class GetdownApp protected void showDocument (String url) { String[] cmdarray; if (RunAnywhere.isWindows()) { - String osName = System.getProperty("os.name"); - if (osName != null && (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1)) { + String osName = System.getProperty("os.name", ""); + if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) { cmdarray = new String[] { "command.com", "/c", "start", "\"" + url + "\"" }; } else { diff --git a/src/main/java/com/threerings/getdown/util/FileUtil.java b/src/main/java/com/threerings/getdown/util/FileUtil.java index 9d6f2ef..f0ebb57 100644 --- a/src/main/java/com/threerings/getdown/util/FileUtil.java +++ b/src/main/java/com/threerings/getdown/util/FileUtil.java @@ -188,19 +188,16 @@ public class FileUtil public static void walkTree (File root, Visitor visitor) { File[] children = root.listFiles(); - if (children != null) { - Deque stack = new ArrayDeque<>(Arrays.asList(children)); - while (!stack.isEmpty()) { - File currentFile = stack.pop(); - if (currentFile.exists()) { - visitor.visit(currentFile); - if (currentFile.isDirectory()) { - File[] currentChildren = currentFile.listFiles(); - if (currentChildren != null) { - for (File file : currentChildren) { - stack.push(file); - } - } + if (children == null) return; + Deque stack = new ArrayDeque<>(Arrays.asList(children)); + while (!stack.isEmpty()) { + File currentFile = stack.pop(); + if (currentFile.exists()) { + visitor.visit(currentFile); + File[] currentChildren = currentFile.listFiles(); + if (currentChildren != null) { + for (File file : currentChildren) { + stack.push(file); } } } diff --git a/src/main/java/com/threerings/getdown/util/LaunchUtil.java b/src/main/java/com/threerings/getdown/util/LaunchUtil.java index 8c6efc7..720515a 100644 --- a/src/main/java/com/threerings/getdown/util/LaunchUtil.java +++ b/src/main/java/com/threerings/getdown/util/LaunchUtil.java @@ -182,13 +182,8 @@ public class LaunchUtil */ public static boolean mustMonitorChildren () { - String osname = System.getProperty("os.name"); - if (osname != null) { - osname = osname.toLowerCase(); - return (osname.indexOf("windows 98") != -1 || osname.indexOf("windows me") != -1); - } else { - return false; - } + String osname = System.getProperty("os.name", "").toLowerCase(); + return (osname.indexOf("windows 98") != -1 || osname.indexOf("windows me") != -1); } /**