On 15/09/2022 16:23, ma...@apache.org wrote:
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
      new 00cf721f14 Refactor to avoid use of Hashtable. No functional change.
00cf721f14 is described below

commit 00cf721f14ac90e7ebc372a5303603ca408fc999
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 15 16:23:49 2022 +0100

     Refactor to avoid use of Hashtable. No functional change.

Any objections to back-porting this?

It changes some protected API for the CGIServlet inner classes (and the CGI Servlet is final). That seems pretty low risk to me.

Mark

---
  java/org/apache/catalina/servlets/CGIServlet.java | 30 +++++++++++------------
  1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/catalina/servlets/CGIServlet.java 
b/java/org/apache/catalina/servlets/CGIServlet.java
index 2f26337a41..dbc941dce5 100644
--- a/java/org/apache/catalina/servlets/CGIServlet.java
+++ b/java/org/apache/catalina/servlets/CGIServlet.java
@@ -29,10 +29,11 @@ import java.nio.file.Files;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.Enumeration;
+import java.util.HashMap;
  import java.util.HashSet;
-import java.util.Hashtable;
  import java.util.List;
  import java.util.Locale;
+import java.util.Map;
  import java.util.Map.Entry;
  import java.util.Set;
  import java.util.StringTokenizer;
@@ -306,7 +307,7 @@ public final class CGIServlet extends HttpServlet {
      private static final Object expandFileLock = new Object();
/** the shell environment variables to be passed to the CGI script */
-    private final Hashtable<String,String> shellEnv = new Hashtable<>();
+    private final Map<String,String> shellEnv = new HashMap<>();
/**
       * Enable creation of script command line arguments from query-string.
@@ -698,7 +699,7 @@ public final class CGIServlet extends HttpServlet {
          private File tmpDir = null;
/** derived cgi environment */
-        private Hashtable<String, String> env = null;
+        private Map<String, String> env = null;
/** cgi command to be invoked */
          private String command = null;
@@ -979,7 +980,7 @@ public final class CGIServlet extends HttpServlet {
               */
// Add the shell environment variables (if any)
-            Hashtable<String, String> envp = new Hashtable<>(shellEnv);
+            Map<String, String> envp = new HashMap<>(shellEnv);
// Add the CGI environment variables
              String sPathInfoOrig = null;
@@ -1317,7 +1318,7 @@ public final class CGIServlet extends HttpServlet {
           * @return   CGI environment
           *
           */
-        protected Hashtable<String,String> getEnvironment() {
+        protected Map<String,String> getEnvironment() {
              return env;
          }
@@ -1416,7 +1417,7 @@ public final class CGIServlet extends HttpServlet {
          private final String command;
/** environment used when invoking the cgi script */
-        private final Hashtable<String,String> env;
+        private final Map<String,String> env;
/** working directory used when invoking the cgi script */
          private final File wd;
@@ -1448,7 +1449,7 @@ public final class CGIServlet extends HttpServlet {
           * @param  params   ArrayList with the script's query command line
           *                  parameters as strings
           */
-        protected CGIRunner(String command, Hashtable<String,String> env,
+        protected CGIRunner(String command, Map<String,String> env,
                              File wd, ArrayList<String> params) {
              this.command = command;
              this.env = env;
@@ -1511,20 +1512,17 @@ public final class CGIServlet extends HttpServlet {
           * key/value pair in the Hashtable to a String in the form
           * "key=value" (hashkey + "=" + hash.get(hashkey).toString())
           *
-         * @param  h   Hashtable to convert
+         * @param  map Hashtable to convert
           *
           * @return     converted string array
           *
           * @exception  NullPointerException   if a hash key has a null value
           *
           */
-        protected String[] hashToStringArray(Hashtable<String,?> h)
-            throws NullPointerException {
-            List<String> list = new ArrayList<>(h.size());
-            Enumeration<String> e = h.keys();
-            while (e.hasMoreElements()) {
-                String k = e.nextElement();
-                list.add(k + "=" + h.get(k).toString());
+        protected String[] mapToStringArray(Map<String,?> map) throws 
NullPointerException {
+            List<String> list = new ArrayList<>(map.size());
+            for (Entry<String,?> entry : map.entrySet()) {
+                list.add(entry.getKey() + "=" + entry.getValue().toString());
              }
              return list.toArray(new String[0]);
          }
@@ -1630,7 +1628,7 @@ public final class CGIServlet extends HttpServlet {
                  rt = Runtime.getRuntime();
                  proc = rt.exec(
                          cmdAndArgs.toArray(new String[0]),
-                        hashToStringArray(env), wd);
+                        mapToStringArray(env), wd);
String sContentLength = env.get("CONTENT_LENGTH");

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to