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

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();
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.