From 6777dd7ea7da5a4330510b1f807538823342c2e7 Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Thu, 9 Aug 2018 12:41:39 +0800 Subject: [PATCH] Fix UnsupportedOperationException in java lookup Mentioned in #412 --- .../org/jackhuang/hmcl/util/JavaVersion.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/JavaVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/JavaVersion.java index 15bdd700a..95f646206 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/JavaVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/JavaVersion.java @@ -22,8 +22,8 @@ import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.concurrent.CountDownLatch; @@ -194,7 +194,7 @@ public final class JavaVersion implements Serializable { javaVersions = queryMacintosh(); break; default: - javaVersions = Collections.emptyList(); + javaVersions = new ArrayList<>(); break; } @@ -214,6 +214,7 @@ public final class JavaVersion implements Serializable { LATCH.countDown(); } + // ==== Linux ==== private static List queryLinux() throws IOException { Path jvmDir = Paths.get("/usr/lib/jvm"); if (Files.isDirectory(jvmDir)) { @@ -234,9 +235,11 @@ public final class JavaVersion implements Serializable { return Collections.emptyList(); } } + // ==== + // ==== OSX ==== private static List queryMacintosh() throws IOException { - LinkedList res = new LinkedList<>(); + List res = new ArrayList<>(); File currentJRE = new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"); if (currentJRE.exists()) @@ -248,9 +251,11 @@ public final class JavaVersion implements Serializable { return res; } + // ==== + // ==== Windows ==== private static List queryWindows() { - LinkedList res = new LinkedList<>(); + List res = new ArrayList<>(); Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\"))); Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\"))); Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\JRE\\"))); @@ -259,7 +264,7 @@ public final class JavaVersion implements Serializable { } private static List querySubFolders(String location) throws IOException, InterruptedException { - List res = new LinkedList<>(); + List res = new ArrayList<>(); String[] cmd = new String[] { "cmd", "/c", "reg", "query", location }; Process process = Runtime.getRuntime().exec(cmd); process.waitFor(); @@ -273,7 +278,7 @@ public final class JavaVersion implements Serializable { } private static List queryRegisterKey(String location) throws IOException, InterruptedException { - List res = new LinkedList<>(); + List res = new ArrayList<>(); for (String java : querySubFolders(location)) { String home = queryRegisterValue(java, "JavaHome"); if (home != null) @@ -306,4 +311,5 @@ public final class JavaVersion implements Serializable { } return null; } + // ==== }