@@ -103,6 +103,9 @@ InputStream execute(String cmd, Object ... args)
103
103
throw new IOException ("Detached from target VM" );
104
104
}
105
105
106
+ // If writeCommand, below, throws IOException, we need to process it further.
107
+ IOException write_ioe = null ;
108
+
106
109
try {
107
110
// enqueue the command to the process.
108
111
if (props .version () == VERSION_1 ) {
@@ -115,31 +118,31 @@ InputStream execute(String cmd, Object ... args)
115
118
// wait for the target VM to connect to the pipe.
116
119
connectPipe (hPipe );
117
120
118
- IOException ioe = null ;
119
-
120
121
if (props .version () == VERSION_2 ) {
121
122
PipeOutputStream writer = new PipeOutputStream (hPipe );
122
123
123
124
try {
124
125
writeCommand (writer , props , cmd , args );
125
126
} catch (IOException x ) {
126
- ioe = x ;
127
+ write_ioe = x ;
127
128
}
128
129
}
129
130
130
- // create an input stream for the pipe
131
- SocketInputStreamImpl in = new SocketInputStreamImpl (hPipe );
132
-
133
- // Process the command completion status
134
- processCompletionStatus (ioe , cmd , in );
135
-
136
- // return the input stream
137
- return in ;
138
-
139
131
} catch (IOException ioe ) {
140
132
closePipe (hPipe );
141
133
throw ioe ;
142
134
}
135
+
136
+ // create an input stream for the pipe
137
+ SocketInputStreamImpl in = new SocketInputStreamImpl (hPipe );
138
+
139
+ // Process the command completion status - this closes the stream
140
+ // and thus the pipe if an exception is to be thrown.
141
+ processCompletionStatus (write_ioe , cmd , in );
142
+
143
+ // return the input stream
144
+ return in ;
145
+
143
146
}
144
147
145
148
private static class PipeOutputStream implements AttachOutputStream {
0 commit comments