From a796b82a16e883976e7f26b4c9d3b4efb5798626 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:57:33 +0700 Subject: [PATCH] [FIX] JavaHelper NPE --- .../src/main/java/pro/gravit/utils/helper/JavaHelper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java index 8fa7cb7e..a0467b27 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java @@ -76,10 +76,13 @@ public synchronized static List findJava() { if (Files.exists(javaExecPath)) { javaExecPath = javaExecPath.toRealPath(); p1 = javaExecPath.getParent().getParent(); + if(p1 == null) { + continue; + } tryAddJava(javaPaths, result, JavaVersion.getByPath(p1)); trySearchJava(javaPaths, result, p1.getParent()); } - } catch (InvalidPathException ignored) { + } catch (InvalidPathException | NullPointerException ignored) { } catch (IOException e) { LogHelper.error(e); @@ -128,7 +131,7 @@ public static boolean tryAddJava(List javaPaths, List resul } public static void trySearchJava(List javaPaths, List result, Path path) throws IOException { - if (!Files.isDirectory(path)) return; + if (path == null || !Files.isDirectory(path)) return; Files.list(path).filter(p -> Files.exists(p.resolve("bin").resolve(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? "java.exe" : "java"))).forEach(e -> { try { tryAddJava(javaPaths, result, JavaVersion.getByPath(e));