From c3f169823f690371ecfdd2d1b3b07a5749438cf1 Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Fri, 9 Oct 2026 07:59:38 +0000 Subject: [PATCH] fix(ghidra): do not run Java from a relative JAVA_HOME in doctor and setup The installation inspection rejected a relative JAVA_HOME, but only after it had already probed `/bin/java` with spawnSync. `rea doctor` and `rea setup` therefore ran whatever `jdk/bin/java` (or `bin/java` for an empty JAVA_HOME) the current directory held, while reporting the setting as rejected. Skip the probe when JAVA_HOME is not absolute on the inspected platform. The configuration check still reports the rejection. Co-Authored-By: Claude Opus 5.5 --- src/ghidra/GhidraInstallation.test.ts | 30 +++++++++++++++++++++++++++ src/ghidra/GhidraInstallation.ts | 13 ++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) 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, }; };