You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/12/31 13:40:52 UTC

(commons-exec) branch master updated (0a2e561e -> 98105c19)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-exec.git


    from 0a2e561e Remove dead comment
     new c4a76494 Remove dead comment
     new 98105c19 Avoid NullPointerException in MapUtils.prefix(Map, String)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   1 +
 .../environment/DefaultProcessingEnvironment.java  |  70 ++-------------------
 .../org/apache/commons/exec/util/MapUtils.java     |   5 +-
 src/site/resources/images/apache-commons-exec.png  | Bin 0 -> 664955 bytes
 4 files changed, 7 insertions(+), 69 deletions(-)
 create mode 100644 src/site/resources/images/apache-commons-exec.png


(commons-exec) 02/02: Avoid NullPointerException in MapUtils.prefix(Map, String)

Posted by gg...@apache.org.
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

commit 98105c19d49e7bc22f8ad3d4e7ae3c19342c79d3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 31 08:40:46 2023 -0500

    Avoid NullPointerException in MapUtils.prefix(Map, String)
---
 src/changes/changes.xml                                |   1 +
 .../java/org/apache/commons/exec/util/MapUtils.java    |   5 ++---
 src/site/resources/images/apache-commons-exec.png      | Bin 0 -> 664955 bytes
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fb478e99..6542c4e3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,7 @@
             <action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate StringUtils.toString(String[], String) in favor of String.join(CharSequence, CharSequence...).</action>
             <action issue="EXEC-78" dev="ggregory" type="fix">No need to use System.class.getMethod("getenv",...) any more.</action>
             <action issue="EXEC-70" dev="ggregory" type="fix">Delegate thread creation to java.util.concurrent.ThreadFactory.</action>
+            <action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in MapUtils.prefix(Map, String).</action>
             <!-- REMOVE -->
             <action dev="ggregory" type="remove" due-to="Gary Gregory">Deprecate DefaultExecuteResultHandler.waitFor(long).</action>
             <action dev="ggregory" type="remove" due-to="Gary Gregory">Deprecate ExecuteWatchdog.ExecuteWatchdog(long).</action>
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 76048fba..cdf7eb35 100644
--- a/src/main/java/org/apache/commons/exec/util/MapUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/MapUtils.java
@@ -19,6 +19,7 @@ package org.apache.commons.exec.util;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Helper classes to manipulate maps to pass substition map to the CommandLine. This class is not part of the public API and could change without warning.
@@ -73,9 +74,7 @@ public class MapUtils {
         }
         final Map<String, V> result = new HashMap<>();
         for (final Map.Entry<K, V> entry : source.entrySet()) {
-            final K key = entry.getKey();
-            final V value = entry.getValue();
-            result.put(prefix + '.' + key.toString(), value);
+            result.put(prefix + '.' + Objects.toString(entry.getKey(), ""), entry.getValue());
         }
         return result;
     }
diff --git a/src/site/resources/images/apache-commons-exec.png b/src/site/resources/images/apache-commons-exec.png
new file mode 100644
index 00000000..0329c976
Binary files /dev/null and b/src/site/resources/images/apache-commons-exec.png differ


(commons-exec) 01/02: Remove dead comment

Posted by gg...@apache.org.
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

commit c4a764947c40a482c90c3a9df0833d6fa1b95050
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 31 08:35:57 2023 -0500

    Remove dead comment
    
    - Javadoc
    - Inline single-use local variable
---
 .../environment/DefaultProcessingEnvironment.java  | 70 ++--------------------
 1 file changed, 4 insertions(+), 66 deletions(-)

diff --git a/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java b/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
index 0fb8d846..7b3577b4 100644
--- a/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
+++ b/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java
@@ -32,9 +32,6 @@ import org.apache.commons.exec.OS;
  */
 public class DefaultProcessingEnvironment {
 
-    /** The line separator of the system */
-//    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
-
     /** The environment variables of the process */
     protected Map<String, String> procEnvironment;
 
@@ -51,47 +48,16 @@ public class DefaultProcessingEnvironment {
     }
 
     /**
-     * Find the list of environment variables for this process.
+     * Creates the list of environment variables for this process.
      *
      * @return a amp containing the environment variables.
      * @throws IOException the operation failed.
      */
     protected Map<String, String> createProcEnvironment() throws IOException {
         if (procEnvironment == null) {
-            final Map<String, String> env = System.getenv();
             procEnvironment = createEnvironmentMap();
-            procEnvironment.putAll(env);
+            procEnvironment.putAll(System.getenv());
         }
-
-// No longer needed
-//        if (procEnvironment == null) {
-//            procEnvironment = createEnvironmentMap();
-//            final BufferedReader in = runProcEnvCommand();
-//
-//            String var = null;
-//            String line;
-//            while ((line = in.readLine()) != null) {
-//                if (line.indexOf('=') == -1) {
-//                    // Chunk part of previous env var (UNIX env vars can
-//                    // contain embedded new lines).
-//                    if (var == null) {
-//                        var = LINE_SEPARATOR + line;
-//                    } else {
-//                        var += LINE_SEPARATOR + line;
-//                    }
-//                } else {
-//                    // New env var...append the previous one if we have it.
-//                    if (var != null) {
-//                        EnvironmentUtils.addVariableToEnvironment(procEnvironment, var);
-//                    }
-//                    var = line;
-//                }
-//            }
-//            // Since we "look ahead" before adding, there's one last env var.
-//            if (var != null) {
-//                EnvironmentUtils.addVariableToEnvironment(procEnvironment, var);
-//            }
-//        }
         return procEnvironment;
     }
 
@@ -149,17 +115,15 @@ public class DefaultProcessingEnvironment {
     }
 
     /**
-     * Find the list of environment variables for this process.
+     * Gets the list of environment variables for this process.
      *
      * @return a map containing the environment variables.
      * @throws IOException obtaining the environment variables failed.
      */
     public synchronized Map<String, String> getProcEnvironment() throws IOException {
-
         if (procEnvironment == null) {
             procEnvironment = this.createProcEnvironment();
         }
-
         // create a copy of the map just in case that
         // anyone is going to modifiy it, e.g. removing
         // or setting an evironment variable
@@ -168,34 +132,8 @@ public class DefaultProcessingEnvironment {
         return copy;
     }
 
-//    /**
-//     * ByteArrayOutputStream#toString doesn't seem to work reliably on OS/390,
-//     * at least not the way we use it in the execution context.
-//     *
-//     * @param bos
-//     *            the output stream that one wants to read
-//     * @return the output stream as a string, read with special encodings in the
-//     *         case of z/os and os/400
-//     */
-//    private String toString(final ByteArrayOutputStream bos) {
-//        if (OS.isFamilyZOS()) {
-//            try {
-//                return bos.toString("Cp1047");
-//            } catch (final java.io.UnsupportedEncodingException e) {
-//                // noop default encoding used
-//            }
-//        } else if (OS.isFamilyOS400()) {
-//            try {
-//                return bos.toString("Cp500");
-//            } catch (final java.io.UnsupportedEncodingException e) {
-//                // noop default encoding used
-//            }
-//        }
-//        return bos.toString();
-//    }
-
     /**
-     * Start a process to list the environment variables.
+     * Runs a process to list the environment variables.
      *
      * @return a reader containing the output of the process.
      * @throws IOException starting the process failed.