Add Java as a supported output language#101
Merged
Merged
Conversation
| Choice(title="python", value="python"), | ||
| Choice(title="javascript", value="javascript"), | ||
| Choice(title="typescript", value="typescript"), | ||
| Choice(title="java", value="java"), |
Contributor
There was a problem hiding this comment.
Selecting Java creates api_client.java, but the existing run workflow discovers only .py files and launches selected files with the virtualenv Python interpreter. A Java run is therefore omitted from run --ls, reports that no Python scripts exist, or produces a Python syntax error when passed explicitly.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/reverse_api/cli.py
Line: 1086
Comment:
**Java Runs Remain Python-Only**
Selecting Java creates `api_client.java`, but the existing `run` workflow discovers only `.py` files and launches selected files with the virtualenv Python interpreter. A Java run is therefore omitted from `run --ls`, reports that no Python scripts exist, or produces a Python syntax error when passed explicitly.
How can I resolve this? If you propose a fix, please make it concise.
This is likely a transient issue. You can re-trigger a run from the dashboard. |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Owner
|
@greptile review |
added 4 commits
July 22, 2026 12:26
Follows the exact same pattern as python/javascript/typescript(/go):
- New prompt partial (prompts/partials/_language_java.md): uses
java.net.http.HttpClient (built into the JDK since 11, no HTTP
library dependency) and Gson for JSON (the JDK has no built-in JSON
support), packaged as a minimal Maven project with exec-maven-plugin
so it runs with a single command. Same auth-hardcoding/refresh
guidance as the other languages. Also calls out a Java-specific
naming detail: the generated file is named api_client.java (this
generator's lowercase convention), so the top-level class is named
ApiClient but declared package-private (no `public` modifier) -
a public class's filename must exactly match its class name, and
a package-private one doesn't have that restriction while compiling
and running identically.
- base_engineer.py: added "java" to _OUTPUT_LANGUAGE_EXTENSIONS
(.java), _get_language_name() ("Java"), _get_run_command() ("mvn -q
compile exec:java"), and _get_auto_output_files() (pom.xml, always
included for Java - unlike Go/JS's conditional dependency files,
Gson is a hard requirement here since there's no stdlib JSON
alternative, matching typescript's "always" precedent instead).
- cli.py: added Java to the interactive `output_language` config
picker.
- Updated the three docstrings/comments that listed the language set
(config.py, engineer.py, prompts/__init__.py) and README.md's output
language line.
- Tests: mirrored the existing per-language test pattern in
test_base_engineer.py (extension, run command, prompt content) and
test_prompts.py (partial loading) for Java.
Caught and fixed one real bug before this counts as done: my first
draft of the partial included a literal `{ ... }` in prose describing
the class declaration, which crashed load()'s str.format_map() with
a KeyError (it treats any `{...}` in the template as a placeholder to
substitute, not just the documented `{run_command}`-style ones) -
confirmed against the other partials that none of them contain a
literal brace anywhere, for the same reason. Rephrased to avoid it.
Full test suite passes (49/49 in the touched files, run 3x to
confirm) except one pre-existing flaky test unrelated to this change
(test_existing_client_language_falls_back_to_newest_file - a
mtime-resolution race condition; confirmed it fails intermittently
on a clean main checkout with none of these changes too, ~40% of
runs in this environment). ruff check is clean on every file this
touches (8 pre-existing lint errors elsewhere on main, none in the
touched lines).
Two real bugs caught by review bots (greptile-apps) on the PR, both verified against the actual code before fixing: 1. Maven only compiles src/main/java by default, but the partial saved api_client.java at the project root alongside pom.xml. mvn compile would silently skip it, and exec:java would fail to find ApiClient. Fixed by telling the generated POM to override <sourceDirectory> to the project root. 2. The agent's cwd for the whole session is scripts_dir.parent.parent (confirmed in engineer.py's analyze_and_generate -> ClaudeAgentOptions), not scripts_dir itself, while pom.xml is saved under scripts_dir. python/node/npx's run commands share this same cwd gap but take a bare relative filename either way, so it doesn't matter for them in practice (that's why this went unnoticed for the existing three languages) - but Maven hard-fails immediately with no upward search if invoked from a directory with no pom.xml, a sharper failure mode. _get_run_command() now points -f explicitly at this run's own pom.xml path for Java specifically, removing the ambiguity rather than relying on the agent to cd there itself first. Updated test_get_run_command_java to match the new (scripts_dir- dependent, no longer a static string) return value. A third bot finding (cli.py's `run <id> --file` subcommand only discovers *.py scripts and always launches them with the shared venv's python interpreter) is real but pre-existing and out of scope here - confirmed discover_scripts() in utils.py has been Python-only since before javascript/typescript were added, so a Java run is no worse off than an existing JS/TS one already is. Multi-language support for that separate subcommand looks like its own follow-up, not something to fold into a single-language-addition PR. Full test suite passes (49/49, run 2x) except the same pre-existing flaky test noted in the other language PRs. ruff check clean on the touched lines (2 pre-existing unused-import warnings elsewhere in test_base_engineer.py, unrelated).
Same class of bug caught by review bots on the PHP PR, applied here
proactively: _get_run_command()'s "-f \"{path}/pom.xml\"" only looked
safe - manual double-quoting doesn't stop $()/backtick command
substitution inside a double-quoted shell string. Replaced with
shlex.quote(), which correctly single-quotes the whole path when
metacharacters are present. Added a test with a deliberately hostile
path (embedded $(rm -rf ~)) asserting the command round-trips through
shlex.split() back to the literal path.
Full test suite passes (50/50, run 2x) except the same pre-existing
flaky test noted on the other language PRs.
Same root cause cubic flagged on the C# and Ruby PRs: a relative --output-dir leaves scripts_dir relative to the original cwd, but once the agent's cwd moves to scripts_dir.parent.parent (see analyze_and_generate), embedding that same relative string in -f re-interprets it from the new location and points Maven at a doubly- nested, nonexistent pom.xml. Resolve scripts_dir before interpolating it, proactively applying the same fix here before it gets flagged.
kalil0321
force-pushed
the
add-java-output-language
branch
from
July 22, 2026 10:34
c87b55b to
8e0765c
Compare
exec:java invokes main() reflectively in-process, which fails on the package-private ApiClient class this generator requires (a public class would have to match the api_client.java filename). exec:exec spawns a real java process instead, and its <classpath/> element expands with the platform-correct separator on Windows/macOS/Linux. The partial now pins the exact known-good plugin configuration so the agent doesn't have to rediscover this incompatibility during its test attempts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows the exact same pattern as python/javascript/typescript(/go):
publicmodifier) - a public class's filename must exactly match its class name, and a package-private one doesn't have that restriction while compiling and running identically.output_languageconfig picker.Caught and fixed one real bug before this counts as done: my first draft of the partial included a literal
{ ... }in prose describing the class declaration, which crashed load()'s str.format_map() with a KeyError (it treats any{...}in the template as a placeholder to substitute, not just the documented{run_command}-style ones) - confirmed against the other partials that none of them contain a literal brace anywhere, for the same reason. Rephrased to avoid it.Full test suite passes (49/49 in the touched files, run 3x to confirm) except one pre-existing flaky test unrelated to this change (test_existing_client_language_falls_back_to_newest_file - a mtime-resolution race condition; confirmed it fails intermittently on a clean main checkout with none of these changes too, ~40% of runs in this environment). ruff check is clean on every file this touches (8 pre-existing lint errors elsewhere on main, none in the touched lines).
Summary by cubic
Adds Java as a supported output language. Generates a minimal Maven project using
java.net.http.HttpClientandGson, runnable withmvn -q -f path/to/pom.xml compile exec:exec.New Features
output_language: "java"to settings and CLI.api_client.java,README.md, andpom.xmlwithGsonandexec-maven-pluginconfigured to run viaexec:exec..javaand name "Java". Docs and tests updated.Bug Fixes
-fthe run’spom.xml(absolute andshlex.quote-escaped; resolves relativescripts_dir).<sourceDirectory>to.in the POM.exec:execinstead ofexec:javato run the package-privateApiClientreliably across platforms.{...}literal from the Java partial to avoidstr.format_mapKeyError.Written for commit 1a641bb. Summary will update on new commits.
Greptile Summary
This PR adds Java as a supported output language. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "Resolve scripts_dir to an absolute path ..." | Re-trigger Greptile