Skip to content

Commit 80d93ae

Browse files
toymachiner62hierynomus
authored andcommitted
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!
1 parent 42c52e4 commit 80d93ae

File tree

1 file changed

+8
-6
lines changed
  • examples/src/main/java/net/schmizz/sshj/examples

1 file changed

+8
-6
lines changed

examples/src/main/java/net/schmizz/sshj/examples/Exec.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ public static void main(String... args)
2020
try {
2121
ssh.authPublickey(System.getProperty("user.name"));
2222
final Session session = ssh.startSession();
23+
final Command cmd = session.exec("ping -c 1 google.com");
24+
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
25+
cmd.join(5, TimeUnit.SECONDS);
26+
System.out.println("\n** exit status: " + cmd.getExitStatus());
27+
} finally {
2328
try {
24-
final Command cmd = session.exec("ping -c 1 google.com");
25-
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
26-
cmd.join(5, TimeUnit.SECONDS);
27-
System.out.println("\n** exit status: " + cmd.getExitStatus());
28-
} finally {
2929
session.close();
30+
} catch (IOException e) {
31+
// Do Nothing
3032
}
31-
} finally {
33+
3234
ssh.disconnect();
3335
}
3436
}

0 commit comments

Comments
 (0)