(process) Process.exitValue() doesn't match subprocess exit value when negative

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P4
    • None
    • Affects Version/s: 5.0u6
    • Component/s: core-libs

      OPERATING SYSTEM(S):
      Linux ( and probably all Unix based JDKs )

      FULL JDK VERSION(S):
      java full version "1.5.0_06-b05"

      DESCRIPTION:
      The following testcase illustrates the problem.
      ProcessTest.java
      public class ProcessTest {
          public static void main(String argv[]) {
              try {
                  Process p = Runtime.getRuntime().exec("java Test");
                  p.waitFor();
                  System.out.println("exit = " + p.exitValue());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      Test.java
      public class Test
      {
        public static void main(String args[])
        {
          System.exit(-10);
        }
      }

      On Windows one gets
      java ProcessTest
      exit = -10

      On Linux one gets
      java ProcessTest
      exit = 246

      This can be a problem on Unix if the WEXITSTATUS macro is not cast to a signed char before assigning to the return value.

            Assignee:
            Martin Buchholz
            Reporter:
            Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: