From 3c5c2c5cc335c1bb19c4e92bd4f75a715468dd33 Mon Sep 17 00:00:00 2001 From: baptiste Date: Sat, 12 Feb 2011 13:51:01 +0100 Subject: [PATCH] [FIXED HUDSON-8420] With IBM JDK for example, it seems like there's no differentiation between Process InputStream&ErrorStream :-(. This means that closing errorStream will actually close every streams. --- core/src/main/java/hudson/Proc.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/hudson/Proc.java b/core/src/main/java/hudson/Proc.java index 4a215a1e0e..fbc7598130 100644 --- a/core/src/main/java/hudson/Proc.java +++ b/core/src/main/java/hudson/Proc.java @@ -190,20 +190,26 @@ public abstract class Proc { this.cookie = EnvVars.createCookie(); procBuilder.environment().putAll(cookie); this.proc = procBuilder.start(); - copier = new StreamCopyThread(name+": stdout copier", proc.getInputStream(), out); + InputStream procInputStream = proc.getInputStream(); + copier = new StreamCopyThread(name+": stdout copier", procInputStream, out); copier.start(); if(in!=null) new StdinCopyThread(name+": stdin copier",in,proc.getOutputStream()).start(); else proc.getOutputStream().close(); + InputStream procErrorStream = proc.getErrorStream(); if(err!=null) { - copier2 = new StreamCopyThread(name+": stderr copier", proc.getErrorStream(), err); + copier2 = new StreamCopyThread(name+": stderr copier", procErrorStream, err); copier2.start(); } else { - // while this is not discussed in javadoc, even with ProcessBuilder.redirectErrorStream(true), - // Process.getErrorStream() still returns a distinct reader end of a pipe that needs to be closed. - // this is according to the source code of JVM - proc.getErrorStream().close(); + // On IBM JDK5, returned input and error streams might be the same. + // So, in this case, closing one isn't a good idea since it will close both. + if (procErrorStream!=procInputStream) { + // while this is not discussed in javadoc, even with ProcessBuilder.redirectErrorStream(true), + // Process.getErrorStream() still returns a distinct reader end of a pipe that needs to be closed. + // this is according to the source code of HotSpot JVM + procErrorStream.close(); + } copier2 = null; } }