mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
Remove unnecessary nested try/finally (#417)
* Remove unnecessary nested try/finally * This handles the case of your concern. An even better solution would be to have SSHClient and Session implement Auto-Closable so then you don't have to worry about doing anything in the finally block!
This commit is contained in:
committed by
Jeroen van Erp
parent
42c52e4fe6
commit
80d93ae8e7
@@ -20,15 +20,17 @@ public class Exec {
|
||||
try {
|
||||
ssh.authPublickey(System.getProperty("user.name"));
|
||||
final Session session = ssh.startSession();
|
||||
try {
|
||||
final Command cmd = session.exec("ping -c 1 google.com");
|
||||
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
|
||||
cmd.join(5, TimeUnit.SECONDS);
|
||||
System.out.println("\n** exit status: " + cmd.getExitStatus());
|
||||
} finally {
|
||||
try {
|
||||
session.close();
|
||||
} catch (IOException e) {
|
||||
// Do Nothing
|
||||
}
|
||||
} finally {
|
||||
|
||||
ssh.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user