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

Process.waitFor returns incorrect exit status code on linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.1
    • 1.3.0
    • hotspot
    • rc1
    • x86
    • linux



        Name: boT120536 Date: 12/13/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
        Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

        I discovered this bug while running the JUnit test suite's sample tests
        (http://www.junit.org/).

        One of the tests in the suite runs a java VM in a separate process, but passes
        it a "main" class which does not exist. The calling code then traps the
        exit status code of the process and does an assertion check to confirm that
        the exit status of the VM was -1. On linux, the exit status is erroneously
        reported as 255, and the assertion fails.

                public void testError() throws Exception {
                        execTest("junit.tests.BogusDude", -1);
                }
                
                void execTest(String testClass, int expected) throws Exception {
                        String java=
             System.getProperty("java.home")+File.separator+"bin"+File.separator+"java";
                        String cp= System.getProperty("java.class.path");
                        String [] cmd= { java, "-cp", cp, "junit.textui.TestRunner",
        testClass};
                        Process p= Runtime.getRuntime().exec(cmd);
                        InputStream i= p.getInputStream();
                        int b;
                        while((b= i.read()) != -1)
                                ; //System.out.write(b);
                        int rc= p.waitFor();
                        assertEquals(expected, rc);
                }

        This reports an assertion error: expected -1, but got 255.

        A member of the JUnit list offered the following explanation:

                    "This is a bug in the JVM implementation.

                    So, I don?t know about Red Hat, but with Blackdown, getting 255
        instead of -1 is a missing cast in the JVM.

                    In a JVM file (UNIXProcess.c??), the offend line
                    probably reads:
                        exit_val = WEXITSTATUS(status);
                    it should read
                        exit_val = (signed char)WEXITSTATUS(status)
                    or something like that.

                    Complain to the JVM implementor."
        (Review ID: 113722)
        ======================================================================

              hhuangsunw Hui Huang (Inactive)
              bonealsunw Bret O'neal (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: