Repository navigation
fix(ghidra): resolve keg-only Homebrew openjdk on macOS (#4556) - #4557
Conversation
Fixes an issue where the `ghidra-java` check fails when OpenJDK is installed via Homebrew on macOS (where it is keg-only and not added to `PATH` or resolved by `java_home`). - **Problem:** When `options.javaHome` is undefined, the provider defaulted to a bare `"java"` command, causing valid Homebrew OpenJDK installations to be reported as missing dependencies. - **Solution:** Replaced the single fallback with an absolute candidate list (`javaCandidates`) that probes standard Homebrew OpenJDK paths (`/opt/homebrew/opt/openjdk/...` and `/usr/local/opt/openjdk/...`) before falling back to `"java"`. All candidates are absolute, preserving existing constraints and current behavior.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
looks good! |
[Medium impact] Changes how the system finds Java on macOS. The PR should not merge until a failing macOS Java launcher allows Homebrew discovery to continue. Findings
Fix with agent prompt### Issue 1
src/ghidra/GhidraInstallation.ts:459-464
If `/usr/bin/java` is an executable macOS launcher with no registered JDK, this check returns `"java"` before checking Homebrew. The launcher then fails, and the single `probeJava` call never tries the installed Homebrew JDK. The setup described in the PR still fails `rea doctor`.
Probe the selected command before accepting it, and try Homebrew when it cannot provide a usable JDK. Add a test with an executable but failing `/usr/bin/java`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds macOS Homebrew OpenJDK discovery when no
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[No configured javaHome on macOS] --> B{Executable java on PATH?}
B -->|Yes| C[Select bare java]
B -->|No| D[Select first executable Homebrew Java]
D --> E[Probe selected command]
C --> E
E -->|Usable JDK| F[Continue installation checks]
E -->|Probe fails| G[Report failure without trying another candidate]
Reviews (4) · Last reviewed commit: "fix(ghidra): resolve Homebrew Java disco..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 139537c1e5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…uto#4556) Fixes a TypeScript compilation error (`TS2322` and `TS2345`) in `src/ghidra/GhidraInstallation.ts` where `options.javaHome` was inferred as `string | undefined` inside `path.join()`. - **Problem:** The ternary operator structure prevented TypeScript from narrowing `options.javaHome` to `string` in the `path.join()` call when `options.javaHome` was defined, causing CI compile checks to fail. - **Solution:** Refactored the `javaCandidates` assignment using an immediately invoked function expression (IIFE) with an explicit `if (options.javaHome === undefined)` check. This properly narrows `options.javaHome` to `string` in the non-undefined branch while keeping the same logic and Homebrew OpenJDK paths intact.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4709e43383
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…luto#4556) Updates the Homebrew OpenJDK candidate ordering in `src/ghidra/GhidraInstallation.ts` to be architecture-aware, addressing review feedback regarding cross-architecture runs (e.g., x64 under Rosetta on Apple Silicon). - **Problem:** Previously, `/opt/homebrew` was always checked before `/usr/local`. When running REA as an x64 process under Rosetta on Apple Silicon, this could incorrectly select an ARM64 JDK over an Intel/x64 one, triggering a `nativeDecompilerCheck` failure and missing the valid fallback. - **Solution:** Dynamically orders `javaCandidates` based on the runtime `architecture`. On `arm64`, `/opt/homebrew` is prioritized; on `x64`, `/usr/local` is prioritized. Bare `"java"` remains first in both cases to preserve standard PATH resolution.
Preserve typed Java probe failures and rejection of relative JAVA_HOME from main. Resolve PATH candidates against the caller environment, limit Homebrew discovery to macOS, and cover architecture preference and explicit selection.
| const javaOnPath = options.environment.PATH?.split(":").some( | ||
| (directory) => | ||
| path.isAbsolute(directory) && | ||
| host.executable(path.join(directory, "java")), | ||
| ); | ||
| if (javaOnPath) return "java"; |
There was a problem hiding this comment.
Java launcher blocks Homebrew fallback
If /usr/bin/java is an executable macOS launcher with no registered JDK, this check returns "java" before checking Homebrew. The launcher then fails, and the single probeJava call never tries the installed Homebrew JDK. The setup described in the PR still fails rea doctor.
Probe the selected command before accepting it, and try Homebrew when it cannot provide a usable JDK. Add a test with an executable but failing /usr/bin/java.
Knowledge Base Used: Ghidra integration
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraInstallation.ts
Line: 459-464
Comment:
**Java launcher blocks Homebrew fallback**
If `/usr/bin/java` is an executable macOS launcher with no registered JDK, this check returns `"java"` before checking Homebrew. The launcher then fails, and the single `probeJava` call never tries the installed Homebrew JDK. The setup described in the PR still fails `rea doctor`.
Probe the selected command before accepting it, and try Homebrew when it cannot provide a usable JDK. Add a test with an executable but failing `/usr/bin/java`.
**Knowledge Base Used:** [Ghidra integration](https://app.greptile.com/pre/-/custom-context/knowledge-base/morluto/rea/-/docs/ghidra-integration.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0accec689
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| path.isAbsolute(directory) && | ||
| host.executable(path.join(directory, "java")), | ||
| ); | ||
| if (javaOnPath) return "java"; |
There was a problem hiding this comment.
Keep probing after the macOS Java stub fails
When macOS has only an unregistered keg-only JDK and PATH includes /usr/bin (the normal PATH=/usr/bin:/bin:... case), /usr/bin/java is still executable even though it exits with the system-stub error; the repository exercises that state in scripts/verify/android/failure-recovery.mjs:120-129. javaOnPath is therefore true, this branch probes bare java, and the single probe fails without ever trying either Homebrew keg, so the change still reports the exact installation it is meant to discover. Continue to the architecture-matching keg when the system wrapper is unavailable; the fake-host test's executable-only PATH model does not cover this real provider state.
AGENTS.md reference: AGENTS.md:L79-L79
Useful? React with 👍 / 👎.
| const javaOnPath = options.environment.PATH?.split(":").some( | ||
| (directory) => | ||
| path.isAbsolute(directory) && | ||
| host.executable(path.join(directory, "java")), |
There was a problem hiding this comment.
Return the absolute PATH candidate that was checked
When macOS PATH has a relative or empty entry before a valid absolute one (for example PATH=.:/usr/bin) and the working directory contains an executable java, this scan ignores the relative entry, observes /usr/bin/java, and then returns bare java; probeGhidraJava passes the unchanged PATH to spawnSync (src/ghidra/GhidraJavaProbe.ts:93-108), so it actually executes ./java first. This defeats the stated working-directory exclusion and can record and launch a different JDK than the absolute candidate that was checked; retain and return the matched absolute path instead.
AGENTS.md reference: AGENTS.md:L13-L13
Useful? React with 👍 / 👎.
Fixes an issue where
rea doctor --provider ghidrafails theghidra-javacheck on macOS when OpenJDK is installed via Homebrew. Homebrew'sopenjdkis keg-only, so it is neither onPATHnor resolved by/usr/libexec/java_home.Fixes #4556
Problem and expected behavior
Problem: When
options.javaHomeis undefined, the provider defaulted to a bare"java"command. On a default macOS setup with Homebrew (brew install ghidra openjdk),javais not available onPATH, causing REA to reportdetail: javawith statusmissing_dependencyeven though a fully functional JDK exists in Homebrew's keg directory.Expected behavior:
ghidra-javachecks standard Homebrew installation paths for a usable JDK before reporting it as missing, allowingrea doctorto pass without requiring manualJAVA_HOMEconfiguration.Change and scope
When
javaHomeis unset on macOS, preserve Java on the caller's absolute PATH entries; otherwise check the standard Homebrew OpenJDK paths, preferring/opt/homebrewfor arm64 and/usr/localfor x64. Retain the bare Java command if no Homebrew executable is found. ExplicitJAVA_HOMEremains authoritative, and Linux/Windows keep their existing selection.The merge resolution preserves main's typed Java probe results and its refusal to execute relative
JAVA_HOMEpaths. Discovery checks absolute executable paths rather than interpreting a file namedjavain the working directory as a PATH match. Added six regression cases for macOS architecture preference, caller PATH, explicit JAVA_HOME, and Linux/Windows selection.Contract and boundary impact
ghidraprovider admission / setup check (inspectGhidraInstallation).darwin/arm64anddarwin/x64) with Homebrew-installed OpenJDK.Expected effects:
Evidence and regression coverage
brew install ghidra openjdkandJAVA_HOMEunset,rea doctor --provider ghidrareturnedghidra-java: ok: false, detail: java.rea doctor --provider ghidranow passes all checks includingghidra-java.For evidence-bearing changes:
Merge-resolution validation
Merged main at
360626434inc0accec68. Executed with Node 24.18.0 on macOS:npm run test:focused -- src/ghidra/GhidraInstallation.test.ts src/ghidra/GhidraJavaProbe.test.ts tests/boundary/filesystem/ghidraJavaProbe.test.ts tests/boundary/cli/ghidraJavaDoctor.test.ts: passed, 121 tests across four files. Discovery uses simulated host observations; doctor tests use controlled Java processes.npm run check:fast: passed (typecheck and lint).git diff origin/main...HEAD --check: passed.Original author validation (before merge resolution)
env -u JAVA_HOME GHIDRA_INSTALL_DIR=/opt/homebrew/Cellar/ghidra/12.1.4/libexec PATH="/usr/bin:/bin:/opt/homebrew/bin" rea doctor --provider ghidra—ghidra-javareportsok: true.Compatibility, safety, and release
darwin/arm64).Author readiness
Human owner:
Before merge
type(scope): outcome.