-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
b02
-
x86
-
linux
-
Not verified
Name: tb29552 Date: 05/07/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Glibc: glibc-2.1.3-18cl
Kernel: Linux localhost.localdomain 2.2.17-14cl #1
Distribution: could not be determined (probably Connectiva
6.0, which is equivalent to Red hat 7.0)
A DESCRIPTION OF THE PROBLEM :
When a process lauches another and waits for it to finish by
the Process.waitFor() method, the value returned has nothing
to do with the value put into the System.exit(value) by the
launched process if value > 127.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Execute the TestLauncher class
2.See the results
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected (sample):
% uname -sr
SunOS 5.8
% java -showversion TestLauncher
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
Testing subprocess return codes from: 0 to: 129
0..25..50..75..100..125..129
Nothing unusual detected during this run.
Actual (sample):
% uname -sr
Linux 2.2.12-20smp
% java -showversion TestLauncher
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
Testing subprocess return codes from: 0 to: 129
0..25..50..75..100..125..ERROR --> Expected return code: 128 Process exited with: -128
ERROR --> Expected return code: 129 Process exited with: -127
129
java.lang.Error: 2 Errors detected during this run.
at TestLauncher.run(TestLauncher.java:110)
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Main class:
import java.io.*;
public class TestLauncher extends Thread {
long errorCount = 0;
private Process initiateProcess(int code) {
Process p = null;
try {
p = Runtime.getRuntime().exec("java TestProcess " + String.valueOf(code));
try {
p.getOutputStream().close();
} catch(Exception e) {
System.out.println("Error closing process stream: " + e);
}
} catch(Exception e) {
System.out.println("Error while starting process. Exiting... " + e);
System.exit(1);
}
return p;
}
public void run() {
final int startValue = 0;
final int endValue = 129;
Process p;
try {
System.out.println("Testing subprocess return codes from: " +
startValue + " to: " + endValue);
for (int i = startValue; i <= endValue; i++) {
if ((i % 25) == 0) {
System.out.print(java.lang.Integer.toString(i) + "..");
}
p = this.initiateProcess(i);
int exitValue = p.waitFor();
p.destroy();
if (exitValue != i) {
System.err.print("ERROR -->");
System.err.print(" Expected return code: " + i);
System.err.println(" Process exited with: " +
exitValue);
errorCount++;
}
}
System.out.println(endValue);
} catch(Exception e) {
e.printStackTrace();
} finally {
if (errorCount > 0) {
throw new Error(java.lang.Long.toString(errorCount) +
" Errors detected during this run.");
} else {
System.out.println("Nothing unusual detected during this run.");
}
}
}
public static void main(String[] args) {
TestLauncher launcher = new TestLauncher ();
launcher.start();
}
}
_______________________________________________________
Aux class:
//_______________________________________________________
public class TestProcess {
public static void main(String []argv) {
System.exit(Integer.parseInt(argv[0]));
}
}
________________________________________________________
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
The problem occurs when the exit code is larger than 127. If
one can avoid using values within the "problematic" range,
there's no harm.
(Review ID: 146108)
======================================================================
- relates to
-
JDK-4397968 Process.waitFor returns incorrect exit status code on linux
-
- Closed
-
-
JDK-4706731 LIN64: nsk/jdwp/VirtualMachine/Exit/exit001 gens wrong exit code
-
- Closed
-