Skip to content

Fix #13405: Do not capture JVM stderr notices into jvm.config options - #13447

Merged
gnodet merged 5 commits into
apache:masterfrom
Yashisinghal285:fix-jvm-config-tool-options
Oct 14, 2026
Merged

gnodet merged 5 commits into
apache:masterfrom
Yashisinghal285:fix-jvm-config-tool-options

Conversation

@Yashisinghal285

Copy link
Copy Markdown
Contributor

Fixes #13405

Problem

In bin/mvn, concat_lines executes JvmConfigParser.java and captures output with 2>&1. When JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, or _JAVA_OPTIONS is set, the JVM prints notices such as Picked up JAVA_TOOL_OPTIONS: ... to stderr. Because stderr was merged into stdout, the notice was captured into MAVEN_OPTS, causing the JVM to treat Picked (or NOTE:) as the main class name on launch.

Solution

  • Separate stdout from stderr when executing JvmConfigParser.java in bin/mvn.
  • Redirect stderr to a temporary file and only display it if the parser exits with a non-zero code.
  • Added test-mvn-jvm-config.sh to verify that JVM notices do not pollute JVM arguments and that parser errors are still reported.
  • Added the test script to the shell-script-tests profile in apache-maven/pom.xml.

Note: Please consider backporting to maven-4.0.x as well, as this affects 4.0.0-rc-7.

Verification

Verified with Git Bash / POSIX test runners:

  • sh apache-maven/src/test/scripts/test-mvn-jvm-config.sh (all assertions pass)
  • sh apache-maven/src/test/scripts/test-mvn-path-conversion.sh (all assertions pass)

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two advisory notes on the stderr-separation approach.

The fix correctly isolates JVM stderr notices (e.g. JAVA_TOOL_OPTIONS) from the parsed JVM options — that's the right approach and the new test script is a solid addition.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread apache-maven/src/assembly/maven/bin/mvn Resolved
Comment thread apache-maven/src/assembly/maven/bin/mvn Resolved

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — both advisory findings have been addressed, but the new test script has a critical stub bug that prevents it from verifying the fix.

Prior findings status:

  • 💡 Missing signal trap — ✅ addressed: trap 'rm -f "$parser_stderr_file"' EXIT INT TERM added immediately after mktemp
  • 💡 elif silently drops stdout in error path — ✅ addressed: replaced with two separate if blocks so both stderr and stdout are always printed on parser failure

New finding: The java stub's JvmConfigParser emulation never fires — see inline comment.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

… source-launch (.java)

The java stub matched $1 against '*JvmConfigParser.java)' (source-launch
convention), but the mvn script invokes the precompiled class:

  "$JAVACMD" -cp "$MAVEN_HOME/bin" JvmConfigParser <config> <basedir>

With the precompiled invocation, $1=-cp, $2=<bin-dir>, $3=JvmConfigParser,
$4=<jvm.config path>. The old pattern never matched, so the stub fell through
to the generic arg-printer and the jvm.config options were never parsed into
MAVEN_OPTS — all assertions silently passed without verifying the primary fix.

Fix: match on $3 and read the config file from $4.
@gnodet gnodet added bug Something isn't working mvn4 backport-to-4.0.x backport-to-3.10.x Should be backported to maven-3.10.x labels Oct 14, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — all 3 findings have been addressed.

  • 💡 Missing signal trap — ✅ addressed: trap 'rm -f "$parser_stderr_file"' EXIT INT TERM added immediately after mktemp
  • 💡 elif silently drops stdout in error path — ✅ addressed: replaced with two separate if blocks
  • ⚠️ Broken stub: JvmConfigParser emulation never fires — ✅ addressed: case "$3" in JvmConfigParser) now correctly matches the precompiled invocation and reads the config from $4

The test stub fix in the last commit is correct. The eval-based launch in bin/mvn means quoted-token output from the JvmConfigParser stub is properly handled by eval exec "$cmd", and the bracketed args in the main launch stub will match the [-Xmx512m] assertions. The <skip>${skipTests}</skip> pattern in pom.xml is consistent with the existing shell script test executions.

LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet removed the backport-to-3.10.x Should be backported to maven-3.10.x label Oct 14, 2026
@gnodet gnodet mentioned this pull request Oct 14, 2026
2 tasks
@Yashisinghal285

Copy link
Copy Markdown
Contributor Author

Thank you for the review and approval, @gnodet!

@gnodet gnodet added the java Pull requests that update Java code label Oct 14, 2026
@gnodet gnodet added this to the 4.1.0 milestone Oct 14, 2026
@gnodet
gnodet merged commit ba60498 into apache:master Oct 14, 2026
22 checks passed
gnodet added a commit that referenced this pull request Oct 15, 2026
…into jvm.config options (#13530)

- Separate stdout from stderr in bin/mvn when executing JvmConfigParser.java
- Redirect stderr to a temporary file; display it only on non-zero exit to avoid polluting MAVEN_OPTS with JVM tool notices (JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, _JAVA_OPTIONS)
- Add test-mvn-jvm-config.sh to verify JVM notices do not pollute JVM arguments and parser errors are still reported
- Register the test script in the shell-script-tests profile in apache-maven/pom.xml

Backport of #13447

Co-authored-by: Yashi Singhal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code mvn4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven 4 does not start when JAVA_TOOL_OPTIONS is set and the project has .mvn/jvm.config

3 participants