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

(process) Process.waitFor() no longer returns negative integers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • sparc
    • solaris_8

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java Hotspot(TM) Server VM (build 1.5.0-b64, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      SunOS 5.8

      A DESCRIPTION OF THE PROBLEM :
      java.lang.Process.waitFor() is supposed to return an int. This works fine in Java 1.4.2, but not in Java 1.5.0. I have code that expects a negative return code of "-99". However, this gets returned as "157" in this line of code:

      int status = p.waitFor(); // Process p

        To fix this, I have to cast the integer return to a byte:

      int status = (byte)p.waitFor();


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I call a C++ application using Runtime.getRuntime().exec(). The C++ application returns with "exit(-99)". I also tried "return -99" and get the same results. On the java side, p.waitFor() returns "157" instead of "-99". However, this code works perfectly in Java 1.4.2. It appears that Java 1.5.0 is internally not allowing negative integer values to be returned. (157 + 99 = 256).
        


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected -99 to be returned, but got 157 on the Java side.
      ACTUAL -
      Java side gets return status of 157 instead of -99.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Here is a snippet of the code:

      JAVA SIDE:
      public static void main()
      {
        Process p = Runtime.getRuntime().exec("C++_appplication_path");
                                                         // replace with path to C++ app
        int status = p.waitFor();
        // status gets 157 instead of -99
      }

      C++ SIDE:
      int main
      {
      exit(-99); // or return -99 works the same too
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Cast the return of Process.waitFor() to a byte as follows:
      int status = (byte)p.waitFor();

      Release Regression From : 1.4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

            martin Martin Buchholz
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: