accidental close on finally block

This commit is contained in:
Adrian Cole 2012-03-08 16:51:09 -08:00
parent dd7b16075e
commit e39fc48901
1 changed files with 18 additions and 22 deletions

View File

@ -504,10 +504,10 @@ public class SshjSshClient implements SshClient {
return acquire(new ExecConnection(command));
}
class ExecChannelConnection implements Connection<ExecChannel> {
private final String command;
private SessionChannel session;
private Command output;
ExecChannelConnection(String command) {
this.command = checkNotNull(command, "command");
@ -515,22 +515,20 @@ public class SshjSshClient implements SshClient {
@Override
public void clear() {
if (session != null)
Closeables.closeQuietly(output);
Closeables.closeQuietly(session);
}
@Override
public ExecChannel create() throws Exception {
try {
session = SessionChannel.class.cast(acquire(execConnection()));
Command output = session.exec(command);
output.join(timeoutMillis, TimeUnit.SECONDS);
return new ExecChannel(session.getOutputStream(), session.getInputStream(), session.getErrorStream(),
output = session.exec(command);
return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(),
new Supplier<Integer>() {
@Override
public Integer get() {
return session.getExitStatus();
return output.getExitStatus();
}
}, new Closeable() {
@ -541,9 +539,7 @@ public class SshjSshClient implements SshClient {
}
});
} finally {
clear();
}
}
@Override