sessionTarget = jsch.getSession(backupUser, backupHost, backupPort);
Here in this line, getSession()
method can throw an Exception, and hence the variables sessionTarget
and channelTarget
will be null, and in the finally block, you are accessing those variables, which may cause null pointer exception.
To avoid this, in the finally block check for null before accessing the variable.
finally {
if (channelTarget != null) {
channelTarget.exit();
channelTarget.disconnect();
}
if (sessionTarget != null ) {
sessionTarget.disconnect();
}
}