diff --git a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
index 2d0d3fdd8..fd81f61c9 100644
--- a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
+++ b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
@@ -56,26 +56,30 @@ public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectT
private static final String SUREFIRE_ARGS_SET = """
- --argLineItem=surefireArgLineValue
+ --argLineItem=surefireArgLineValue --undefinedArgLineItem=${undefinedProperty}
surefireProp1Value
+ ${undefinedProperty}
surefireEnvironmentVariables1Value
+ ${undefinedProperty}
""";
private static final String FAILSAFE_ARGS_SET = """
- --argLineItem=failsafeArgLineValue
+ --argLineItem=failsafeArgLineValue --undefinedArgLineItem=${undefinedProperty}
failsafeProp1Value
+ ${undefiniedProperty}
failsafeEnvironmentVariables1Value
+ ${undefinedProperty}
""";
@@ -144,6 +148,10 @@ public void test_configuration_must_be_updated_with_surefire_config()
// check systemPropertyVariables
assertTrue(argLine.contains("-DsurefireProp1=surefireProp1Value"));
+
+ // check systemPropertyVariables with null value aren't set
+ assertTrue(!argLine.contains("-DsurefireEmptyProp="));
+
}
@Test
@@ -193,6 +201,9 @@ public void test_configuration_must_be_updated_with_failsafe_config()
// check systemPropertyVariables
assertTrue(argLine.contains("-DfailsafeProp1=failsafeProp1Value"));
+
+ // check systemPropertyVariables with null value aren't set
+ assertTrue(!argLine.contains("-DfailsafeEmptyProp="));
}
@Test
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
index 12fab0542..405fd1bec 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
@@ -29,6 +29,7 @@
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -279,7 +280,9 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
launchArguments.add(args.argLine());
}
if(args.systemPropertyVariables() != null) {
- args.systemPropertyVariables().forEach((key, value) -> launchArguments.add("-D" + key + "=" + value));
+ args.systemPropertyVariables().entrySet().stream().filter(e -> e.getKey() != null)
+ .filter(e -> e.getValue() != null)
+ .forEach(e -> launchArguments.add("-D" + e.getKey() + "=" + e.getValue()));
}
copy.setAttribute(LAUNCH_CONFIG_VM_ARGUMENTS, launchArguments.toString());
@@ -295,7 +298,10 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
}
if(args.environmentVariables() != null) {
- copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, args.environmentVariables());
+ Map filteredMap = args.environmentVariables().entrySet().stream()
+ .filter(entry -> entry.getKey() != null && entry.getValue() != null)
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, filteredMap);
}
copy.doSave();