Commits

James Dumay committed b386ee0

BAM-811 fix npe when cancel is called and no process has been created.

Comments (0)

Files changed (2)

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

             errorPump.cancel();
         }
 
-        if (OS_NAME.startsWith("Windows"))
+        if (process != null)
         {
-            try
+            if (OS_NAME.startsWith("Windows"))
             {
-                final WinProcess winProcess = new WinProcess(process);
-                winProcess.killRecursively();
+                try
+                {
+                    final WinProcess winProcess = new WinProcess(process);
+                    winProcess.killRecursively();
+                }
+                catch (UnsatisfiedLinkError e)
+                {
+                    log.error("Could not recursively kill windows process using winp; falling back to java.lang.Process#destroy", e);
+                    process.destroy();
+                }
             }
-            catch (UnsatisfiedLinkError e)
+            else
             {
-                log.error("Could not recursively kill windows process using winp; falling back to java.lang.Process#destroy", e);
                 process.destroy();
             }
         }
-        else
-        {
-            process.destroy();
-        }
     }
 
     public void setTimeout(long timeout) {

src/test/java/com/atlassian/utils/process/ExternalProcessTest.java

         ExternalProcess process = new ExternalProcessBuilder().command(Arrays.asList("pause")).build();
         process.start();
         process.cancel();
-        assertNotNull(process.getHandler().getException());
     }
 }