From 5b61c9923866f8148caf49f9bb330cc1b8ea78b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Rodr=C3=ADguez?= Date: Wed, 5 Aug 2026 10:09:46 +0200 Subject: [PATCH] Preserve exit values above 127 when reaping children MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a child process exits with a code above 127, Process.waitFor() and Process.exitValue() return a negative number. This happens because VMProcess.nativeReap() incorrectly casts WEXITSTATUS() to jbyte (which is signed) before publishing it, so e.g. exit code 128 is reported as -128 and 250 as -6. In addition, the incorrect values can be mistaken for signal deaths, which Classpath reports as the negative signal number (so -6 is what is reported when a child is killed by SIGABRT). Fix by removing the incorrect jbyte cast. Fixes #54 (BZ#126651) Signed-off-by: Guillermo Rodríguez --- native/jni/java-lang/java_lang_VMProcess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/jni/java-lang/java_lang_VMProcess.c b/native/jni/java-lang/java_lang_VMProcess.c index 9ef2d97a0..6cd2292ac 100644 --- a/native/jni/java-lang/java_lang_VMProcess.c +++ b/native/jni/java-lang/java_lang_VMProcess.c @@ -362,7 +362,7 @@ Java_java_lang_VMProcess_nativeReap (JNIEnv * env, jclass clazz) /* Get exit code; for signal termination return negative signal value XXX */ if (WIFEXITED (status)) - status = (jint) (jbyte) WEXITSTATUS (status); + status = (jint) WEXITSTATUS (status); else if (WIFSIGNALED (status)) status = -(jint) WTERMSIG (status); else