dhananjay6561 opened a new pull request, #3610:
URL: https://github.com/apache/maven-surefire/pull/3610
Fixes #2786.
In a forked run, `systemPropertyVariables` are applied with
`System.setProperty()` after the JVM has started. The default `Locale` is fixed
during JVM startup, so `user.language`, `user.country`, `user.region` and
friends end up in `System.getProperty()` but `Locale.getDefault()` never
changes. That is the behaviour the issue describes, and `argLine` is the only
place where these properties work.
Surefire already handles this class of property: `file.encoding`,
`line.separator`, `java.library.path` and `jdk.map.althashing.threshold` are
listed in `SurefireProperties`, and setting them outside `argLine` logs
```
[WARNING] file.encoding cannot be set as system property, use
<argLine>-Dfile.encoding=...</argLine> instead
```
This PR adds the locale properties (`user.language`, `user.country`,
`user.region`, `user.variant`, `user.script`) to that list, so users get the
same warning instead of a silently ignored setting. Nothing else changes: the
properties are still passed to the fork, and the warning is skipped when the
property is already in `argLine`.
Changes:
- `SurefireProperties`: add the five locale keys to
`KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES`.
- `SurefirePropertiesTest`: new test for
`propertiesThatCannotBeSetASystemProperties()` with the locale keys plus an
unrelated key.
- `systemPropertyVariables` javadoc and the "Special VM Properties" section
of the system properties page list the locale properties.
Verification:
- JDK check of the root cause: a program that calls
`System.setProperty("user.language", "fr")` and
`System.setProperty("user.country", "CA")` still prints the old default from
`Locale.getDefault()` on JDK 21 and 27, while `-Duser.language=fr
-Duser.country=CA` on the command line gives `fr_CA`.
- `mvn -pl maven-surefire-common test -Dtest=SurefirePropertiesTest`: the
new test fails on master (`expected: <[user.variant, user.script,
user.language, user.region, user.country]> but was: <[]>`) and passes with the
change (6 tests, 0 failures).
- `mvn -pl maven-surefire-common spotless:check` is clean.
I did not run the ITs.
---
To make clear that you license your contribution under
the [Apache License Version 2.0, January
2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:
- [x] I hereby declare this contribution to be licensed under the [Apache
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor
License Agreement](https://www.apache.org/licenses/icla.pdf).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]