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 e2ecada9e [SUREFIRE-1892] Stringify non-String systemPropertyVariables 
values (#3592)
e2ecada9e is described below

commit e2ecada9e4f724461fa4e97e0ff76097d30cf3fa
Author: Arturo Bernal <[email protected]>
AuthorDate: Fri Nov 13 09:45:22 2026 +0100

    [SUREFIRE-1892] Stringify non-String systemPropertyVariables values (#3592)
    
    Interpolating an expression like ${settings.offline} into a
    <systemPropertyVariables> entry resolves to its real typed object
    (a Boolean here) rather than a String. Because the setter was
    declared as Map<String, String>, the plugin configurator rejects
    the value outright before the mojo is even invoked:
    "Cannot assign configuration entry ... of type java.lang.Boolean
    to property of type java.lang.String".
    
    Widen the setter to Map<String, ?> so the configurator stops
    enforcing the String-only type, and stringify every value
    explicitly when storing it, matching the field's declared type.
---
 .../maven/plugin/surefire/AbstractSurefireMojo.java   | 19 +++++++++++++++++--
 .../plugin/surefire/AbstractSurefireMojoTest.java     | 11 +++++++++++
 2 files changed, 28 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 84c56d256..15d7e436d 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
@@ -3532,8 +3532,23 @@ public Map<String, String> getSystemPropertyVariables() {
     }
 
     @SuppressWarnings("UnusedDeclaration")
-    public void setSystemPropertyVariables(Map<String, String> 
systemPropertyVariables) {
-        this.systemPropertyVariables = systemPropertyVariables;
+    public void setSystemPropertyVariables(Map<String, ?> 
systemPropertyVariables) {
+        this.systemPropertyVariables =
+                systemPropertyVariables == null ? null : 
stringifyValues(systemPropertyVariables);
+    }
+
+    /**
+     * Interpolation of a {@code systemPropertyVariables} entry such as {@code 
${settings.offline}} can resolve
+     * to a non-String object (e.g. {@code Boolean}), so the configurator must 
accept {@code Map<String, ?>}
+     * rather than {@code Map<String, String>} and this method stringifies 
every value explicitly.
+     */
+    private static Map<String, String> stringifyValues(Map<String, ?> values) {
+        Map<String, String> result = new HashMap<>();
+        for (Entry<String, ?> entry : values.entrySet()) {
+            Object value = entry.getValue();
+            result.put(entry.getKey(), value == null ? null : 
String.valueOf(value));
+        }
+        return result;
     }
 
     /**
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index 9177b0dc2..2366ff04a 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -93,6 +93,7 @@
 import static java.util.Collections.emptyMap;
 import static java.util.Collections.singleton;
 import static java.util.Collections.singletonList;
+import static java.util.Collections.singletonMap;
 import static 
org.apache.maven.artifact.ArtifactUtils.artifactMapByVersionlessId;
 import static 
org.apache.maven.artifact.versioning.VersionRange.createFromVersion;
 import static 
org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
@@ -100,6 +101,7 @@
 import static org.apache.maven.surefire.shared.lang3.JavaVersion.JAVA_RECENT;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
 import static 
org.codehaus.plexus.languages.java.jpms.ModuleNameSource.MODULEDESCRIPTOR;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
@@ -2063,6 +2065,15 @@ public void 
shouldNotWarnWhenIgnoredParametersKeepTheirDefaults() {
         verify(logger, times(0)).warn(anyString());
     }
 
+    @Test
+    public void shouldStringifyNonStringSystemPropertyVariableValues() {
+        Mojo mojo = new Mojo();
+
+        mojo.setSystemPropertyVariables(singletonMap("isOffline", true));
+
+        
assertThat(mojo.getSystemPropertyVariables()).containsExactly(entry("isOffline",
 "true"));
+    }
+
     private void setProjectDepedenciesToMojo(Artifact... deps) {
         for (Artifact dep : deps) {
             mojo.getProjectArtifactMap().put(dep.getGroupId() + ":" + 
dep.getArtifactId(), dep);

Reply via email to