From 3c4c38ea84016bf4c831e6bf26bb1c1c39d74216 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Fri, 22 Apr 2022 01:10:06 +0100 Subject: [PATCH] Improve Java runtime finder resiliency Found some more edge cases in the wild - though to be honest this entire thing is edge cases. Sometimes /release exists, but the actual binaries are in /jre/bin; this commit changes behaviour to look for the two things independently. --- .../launch/runtime/JavaRuntimeFinder.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/launch/runtime/JavaRuntimeFinder.java b/launcher/src/main/java/com/skcraft/launcher/launch/runtime/JavaRuntimeFinder.java index 7af48c84a..456a07577 100644 --- a/launcher/src/main/java/com/skcraft/launcher/launch/runtime/JavaRuntimeFinder.java +++ b/launcher/src/main/java/com/skcraft/launcher/launch/runtime/JavaRuntimeFinder.java @@ -73,6 +73,7 @@ public static JavaRuntime getRuntimeFromPath(String path) { } public static JavaRuntime getRuntimeFromPath(File target) { + // Normalize target to root first if (target.isFile()) { // Probably referring directly to bin/java, back up two levels target = target.getParentFile().getParentFile(); @@ -81,20 +82,26 @@ public static JavaRuntime getRuntimeFromPath(File target) { target = target.getParentFile(); } - { - File jre = new File(target, "jre/release"); - if (jre.isFile()) { - target = jre.getParentFile(); - } + // Find the release file + File releaseFile = new File(target, "release"); + if (!releaseFile.isFile()) { + releaseFile = new File(target, "jre/release"); + // may still not exist - parseFromRelease below will return null if so } - JavaReleaseFile release = JavaReleaseFile.parseFromRelease(target); + // Find the bin folder + File binFolder = new File(target, "bin"); + if (!binFolder.isDirectory()) { + binFolder = new File(target, "jre/bin"); + } + + JavaReleaseFile release = JavaReleaseFile.parseFromRelease(releaseFile.getParentFile()); if (release == null) { // Make some assumptions... - return new JavaRuntime(target, null, true); + return new JavaRuntime(binFolder.getParentFile(), null, true); } - return new JavaRuntime(target, release.getVersion(), release.isArch64Bit()); + return new JavaRuntime(binFolder.getParentFile(), release.getVersion(), release.isArch64Bit()); } private static PlatformRuntimeFinder getRuntimeFinder(Environment env) {