Skip to content

Commit

Permalink
Improve Java runtime finder resiliency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hedgehog1029 committed Apr 22, 2022
1 parent 79b1289 commit 3c4c38e
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 3c4c38e

Please sign in to comment.