From 0338bdcb36f5088e64f95ea7155bdd9237ea8829 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Fri, 1 Apr 2022 20:47:23 +0700 Subject: [PATCH] Crash log: The NPE was able to escape, so catch it! --- .../main/java/net/kdt/pojavlaunch/Tools.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 884f62d36..5d5397079 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -663,19 +663,21 @@ public final class Tools { File fl = new File(dir); File[] files = fl.listFiles(File::isFile); - if (files == null) { - return null; - } long lastMod = Long.MIN_VALUE; File choice = null; - for (File file : files) { - if (file.lastModified() > lastMod) { - choice = file; - lastMod = file.lastModified(); + try { + for (File file : files) { + if (file.lastModified() > lastMod) { + choice = file; + lastMod = file.lastModified(); + } } + } catch (NullPointerException e) { + // fine, let's just return null + // if (files == null) didn't work for some reasons + e.printStackTrace(); } - return choice; }