Commits

James Dumay committed 5b368c6

Fix problem where if environment is null the new environment for windows encoding work around would not be added to the ProcessBuilder

  • Participants
  • Parent commits 4068649

Comments (0)

Files changed (1)

src/main/java/com/atlassian/utils/process/ExternalProcess.java

       * as the user typically won't use characters that aren't defined for his locale. But then again, they might..
      */
     private Process createWinProcess(List<String> command, Map<String, String> environment, File workingDir) throws IOException {
-        Map<String, String> newEnv = environment != null ? new HashMap<String, String>(environment) : new HashMap<String, String>();
-
-        List<String> newCommand = new ArrayList<String>();
+        final List<String> newCommand = new ArrayList<String>();
         newCommand.add("cmd");
         newCommand.add("/A");
         newCommand.add("/C");
         newCommand.add("call");
 
-        if (useWindowsEncodingWorkaround)
-        {
+        if (useWindowsEncodingWorkaround) {
+            Map<String, String> newEnv = environment != null ? new HashMap<String, String>(environment) : new HashMap<String, String>();
             for (int counter = 1; counter < command.size(); counter++) {
                 final String envName = "JENV_" + counter;
                 newCommand.add("%" + envName + "%");
                 newEnv.put(envName, quoteString(command.get(counter)));
             }
-        }
-        else
-        {
+            environment = newEnv;
+        } else {
             newCommand.addAll(command);
         }
 
         if (environment != null)
         {
             pb.environment().putAll(environment);
-            pb.environment().putAll(newEnv);
         }
         return pb.start();
     }