Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8294899

Process.waitFor() throws IllegalThreadStateException when a process on Windows returns an exit code of 259

    XMLWordPrintable

Details

    • b24
    • x86_64
    • windows
    • Verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows (any version), OpenJDK (any version)

      A DESCRIPTION OF THE PROBLEM :
      When a Java application spawns a process on Windows that returns an exit code of 259 (0x103), the call to `Process.waitFor()` throws an IllegalThreadStateException.

      It does this because the implementation method, `waitFor()` in ProcessImpl.java, calls `exitValue()`. In turn, `exitValue()` checks if the exit value is 259, which on Windows is returned when the process has not yet exited. `exitValue()` then goes ahead and throws an exception.

      This can easily be fixed by having `waitFor()` call `getExitCodeProcess()` directly, thus bypassing the check for "not yet exited" since we know it actually has exited. In other words, in https://github.com/openjdk/jdk/blob/master/src/java.base/windows/classes/java/lang/ProcessImpl.java, replace line 575, containing "return exitValue();", with "return getExitCodeProcess(handle);"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a Process that exits with an exit value of 259 on Windows. Call process.waitFor().

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should return 259.
      ACTUAL -
      It throws an exception saying the process has not exited.

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround, but it can be easily fixed in the JDK source.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              rriggs Roger Riggs
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: