diff --git a/src/ghidra/GhidraInstallation.test.ts b/src/ghidra/GhidraInstallation.test.ts index 3c6d46354c..9f42a84ab6 100644 --- a/src/ghidra/GhidraInstallation.test.ts +++ b/src/ghidra/GhidraInstallation.test.ts @@ -413,6 +413,36 @@ describe("Ghidra configuration paths", () => { }, ); + it.each([ + ["linux", "./jdk"], + ["linux", ""], + ["win32", "jdk"], + ] as const)( + "does not run Java from a relative JAVA_HOME (%s %o)", + (platform, javaHome) => { + const probed: string[] = []; + const result = inspectGhidraInstallation( + { + installDir: platform === "win32" ? WINDOWS_INSTALL : INSTALL, + javaHome, + platform, + architecture: "x64", + }, + host({ + probeJava: (command) => { + probed.push(command); + return JAVA; + }, + }), + ); + expect(probed).toEqual([]); + expect(result).toMatchObject({ + status: "unavailable", + rejection: { code: "not_configured" }, + }); + }, + ); + it("judges absolute paths by the inspected platform", () => { const result = inspectGhidraInstallation( { installDir: "C:\\ghidra", platform: "win32", architecture: "x64" }, diff --git a/src/ghidra/GhidraInstallation.ts b/src/ghidra/GhidraInstallation.ts index d0906fb527..bf1371715e 100644 --- a/src/ghidra/GhidraInstallation.ts +++ b/src/ghidra/GhidraInstallation.ts @@ -292,10 +292,15 @@ const installationCoordinates = ( ? undefined : ghidraApplicationProperties(properties), javaCommand, - java: host.probeJava( - javaCommand, - ghidraJavaEnvironment(options.javaHome, process.env, platform), - ), + // The configuration check rejects a relative JAVA_HOME. Probing it would + // run whatever `bin/java` the current directory holds. + java: + options.javaHome === undefined || path.isAbsolute(options.javaHome) + ? host.probeJava( + javaCommand, + ghidraJavaEnvironment(options.javaHome, process.env, platform), + ) + : undefined, }; };