Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BobVul
Copy link
Contributor

@BobVul BobVul commented Jul 21, 2025

Fixes #10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so.

Specifically, this fixes this case:

$env:MAVEN_OPTS='"-Dfoo=bar|baz"'
mvn

by implementing proposed fix 2 from #10937


Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so.
@BobVul BobVul changed the title Avoid parsing MAVEN_OPTS Avoid parsing MAVEN_OPTS (3.9.x) Jul 21, 2025
@BobVul
Copy link
Contributor Author

BobVul commented Jul 21, 2025

I'm a bit unsure of how to add IT tests to 3.9.x -- do they go into the old repo?

@slawekjaranowski
Copy link
Member

I'm a bit unsure of how to add IT tests to 3.9.x -- do they go into the old repo?

Yes for 3.9.x old repo with ITs are used ...
https://github.com/apache/maven-integration-testing

Please fork it, create branch with the same name as in this PR - patch-1 and will be used during build on GH

@slawekjaranowski slawekjaranowski linked an issue Jul 21, 2025 that may be closed by this pull request
@slawekjaranowski slawekjaranowski added the bug Something isn't working label Jul 21, 2025
@BobVul
Copy link
Contributor Author

BobVul commented Jul 21, 2025

I'm a bit unsure of how to add IT tests to 3.9.x -- do they go into the old repo?

Yes for 3.9.x old repo with ITs are used ... https://github.com/apache/maven-integration-testing

Please fork it, create branch with the same name as in this PR - patch-1 and will be used during build on GH

I have added tests under apache/maven-integration-testing#407

At the moment they are still their own file, as the MNG-4559 tests you suggested I extend in #10970 (comment) do not exist in the 3.9.x branch. If it's better to keep the same name in both please let me know and I will amend the PR.

@BobVul
Copy link
Contributor Author

BobVul commented Jul 21, 2025

Ah that's annoying... looks like whether the quotes are retained or not differ between Windows and *nix. This isn't even behaviour changed by this PR, just a difference exposed by the new test :\

"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
if ERRORLEVEL 1 goto skipEnableNativeAccess
set "MAVEN_OPTS=--enable-native-access=ALL-UNNAMED %MAVEN_OPTS%"
set "INTERNAL_MAVEN_OPTS=--enable-native-access=ALL-UNNAMED %INTERNAL_MAVEN_OPTS%"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should expose this new variable. Which means we need to set it to an empty string before trying the line 176, so that a value coming from the user env would not interfere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've pushed a change to clear this variable at the top of the script.

@BobVul
Copy link
Contributor Author

BobVul commented Jul 21, 2025

I have updated the tests for 3.9.x to strip quotes when checking results, and verified it works as expected on Linux (Debian). Unfortunately I do not have any access to macOS so will need to rely on CI to verify those.

Expectation currently is that -Dprop.opts="foo|bar" will result in the property being set to foo|bar on Windows and "foo|bar" on Linux. While this is a bit inconsistent, I don't think this is the correct place to change this existing behaviour.

Fixes apache#10937 by introducing an additional INTERNAL_MAVEN_OPTS for any arguments that need to be inserted by the script. Parsing the externally-defined MAVEN_OPTS variable can lead to incorrect processing of quotes and special characters, so use the separate variable to avoid doing so.
@BobVul BobVul requested a review from gnodet July 22, 2025 14:46
@gnodet gnodet merged commit 256a441 into apache:maven-3.9.x Jul 24, 2025
18 checks passed
@github-actions github-actions bot added this to the 3.9.12 milestone Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mvn3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quoted pipes in MAVEN_OPTS throw errors in 3.9.10+, 4.0.0-rc

4 participants