This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-exec.git
The following commit(s) were added to refs/heads/master by this push: new ce7da84 Init Maps on creation. ce7da84 is described below commit ce7da84482ae133e80d7051d13c21f9ce32ae856 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Feb 28 10:32:11 2021 -0500 Init Maps on creation. --- src/main/java/org/apache/commons/exec/util/MapUtils.java | 11 ++--------- .../java/org/apache/commons/exec/DefaultExecutorTest.java | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/commons/exec/util/MapUtils.java b/src/main/java/org/apache/commons/exec/util/MapUtils.java index cead70d..5d01aee 100644 --- a/src/main/java/org/apache/commons/exec/util/MapUtils.java +++ b/src/main/java/org/apache/commons/exec/util/MapUtils.java @@ -39,15 +39,8 @@ public class MapUtils * the map value type * @return the cloned map */ - public static <K, V> Map<K, V> copy(final Map<K, V> source) { - - if (source == null) { - return null; - } - - final Map<K, V> result = new HashMap<>(); - result.putAll(source); - return result; + public static <K, V> Map<K, V> copy(final Map<K, V> source) { + return source == null ? null : new HashMap<>(source); } /** diff --git a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java index c58b929..5d0402f 100644 --- a/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java +++ b/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java @@ -687,8 +687,7 @@ public class DefaultExecutorTest { */ @Test public void testAddEnvironmentVariables() throws Exception { - final Map<String, String> myEnvVars = new HashMap<>(); - myEnvVars.putAll(EnvironmentUtils.getProcEnvironment()); + final Map<String, String> myEnvVars = new HashMap<>(EnvironmentUtils.getProcEnvironment()); myEnvVars.put("NEW_VAR","NEW_VAL"); exec.execute(new CommandLine(environmentSript), myEnvVars); final String environment = baos.toString().trim(); @@ -698,8 +697,7 @@ public class DefaultExecutorTest { @Test public void testAddEnvironmentVariableEmbeddedQuote() throws Exception { - final Map<String, String> myEnvVars = new HashMap<>(); - myEnvVars.putAll(EnvironmentUtils.getProcEnvironment()); + final Map<String, String> myEnvVars = new HashMap<>(EnvironmentUtils.getProcEnvironment()); final String name = "NEW_VAR"; final String value = "NEW_\"_VAL"; myEnvVars.put(name,value);