This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 8a906f316 Fix #2786: warn when locale properties are set outside
argLine (#3610)
8a906f316 is described below
commit 8a906f31669fbc71eac483d415adb518ca24308c
Author: Dhananjay Aggarwal <[email protected]>
AuthorDate: Sun Nov 22 08:20:06 2026 +0530
Fix #2786: warn when locale properties are set outside argLine (#3610)
* warn when locale properties are set outside argLine
Signed-off-by: dhananjay6561 <[email protected]>
* test that locale properties are flagged for argLine
Signed-off-by: dhananjay6561 <[email protected]>
* list the locale properties in the systemPropertyVariables docs
Signed-off-by: dhananjay6561 <[email protected]>
* mention the locale properties on the system properties page
Signed-off-by: dhananjay6561 <[email protected]>
---------
Signed-off-by: dhananjay6561 <[email protected]>
---
.../maven/plugin/surefire/AbstractSurefireMojo.java | 2 ++
.../maven/plugin/surefire/SurefireProperties.java | 13 +++++++++++--
.../maven/plugin/surefire/SurefirePropertiesTest.java | 18 ++++++++++++++++++
.../src/site/markdown/examples/system-properties.md.vm | 6 ++++++
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index c08a343e4..bcd79c30e 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -400,6 +400,8 @@ public abstract class AbstractSurefireMojo extends
AbstractMojo implements Suref
* <li>{@code file.encoding}</li>
* <li>{@code jdk.map.althashing.threshold}</li>
* <li>{@code line.separator}</li>
+ * <li>{@code user.language}, {@code user.country}, {@code user.region},
{@code user.variant} and
+ * {@code user.script}, which set the default {@code Locale}</li>
* </ul>
*
* @see #systemProperties
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
index 426359753..ec5ae3fd1 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
@@ -44,8 +44,17 @@
* A {@link Properties} implementation that preserves insertion order.
*/
public class SurefireProperties extends Properties implements KeyValueSource {
- private static final Collection<String>
KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES =
- asList("java.library.path", "file.encoding",
"jdk.map.althashing.threshold", "line.separator");
+ private static final Collection<String>
KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES = asList(
+ "java.library.path",
+ "file.encoding",
+ "jdk.map.althashing.threshold",
+ "line.separator",
+ // the default Locale is fixed when the JVM starts
+ "user.language",
+ "user.country",
+ "user.region",
+ "user.variant",
+ "user.script");
private final LinkedHashSet<Object> items = new LinkedHashSet<>();
diff --git
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
index e496bde81..c56746ac3 100644
---
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
+++
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
@@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -30,6 +31,7 @@
import org.apache.maven.surefire.booter.KeyValueSource;
import org.junit.jupiter.api.Test;
+import static java.util.Arrays.asList;
import static java.util.Collections.list;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -133,6 +135,22 @@ public void testCopyPropertiesFrom() {
assertEquals(Arrays.asList("property1", "property2"),
orderedProperties.copyPropertiesFrom(properties));
}
+ @Test
+ public void testLocalePropertiesCannotBeSetAsSystemProperties() {
+ // the JVM fixes the default Locale at startup, so these only take
effect in argLine
+ SurefireProperties properties = new SurefireProperties();
+ properties.setProperty("user.language", "en");
+ properties.setProperty("user.country", "GB");
+ properties.setProperty("user.region", "GB");
+ properties.setProperty("user.variant", "POSIX");
+ properties.setProperty("user.script", "Latn");
+ properties.setProperty("my.property", "value");
+
+ assertEquals(
+ new HashSet<>(asList("user.language", "user.country",
"user.region", "user.variant", "user.script")),
+ properties.propertiesThatCannotBeSetASystemProperties());
+ }
+
private static int size(Iterator<?> iterator) {
int count = 0;
while (iterator.hasNext()) {
diff --git
a/maven-surefire-plugin/src/site/markdown/examples/system-properties.md.vm
b/maven-surefire-plugin/src/site/markdown/examples/system-properties.md.vm
index 5b320b6d6..b92909395 100644
--- a/maven-surefire-plugin/src/site/markdown/examples/system-properties.md.vm
+++ b/maven-surefire-plugin/src/site/markdown/examples/system-properties.md.vm
@@ -151,3 +151,9 @@ Some system properties must be set on the command line of
the forked VM, and can
```xml
<argLine>-Djava.endorsed.dirs=...</argLine>
```
+
+The same applies to the properties that select the default `Locale`
(`user.language`, `user.country`, `user.region`, `user.variant` and
`user.script`). Setting them in `systemPropertyVariables` changes what
`System.getProperty()` returns, but not `Locale.getDefault()`:
+
+```xml
+ <argLine>-Duser.language=en -Duser.country=GB</argLine>
+```