我正在使用 NetBeans
编写一个 SFTP
程序。
我的部分代码:
com.jcraft.jsch.Session sessionTarget = null;
com.jcraft.jsch.ChannelSftp channelTarget = null;
try {
sessionTarget = jsch.getSession(backupUser, backupHost, backupPort);
sessionTarget.setPassword(backupPassword);
sessionTarget.setConfig("StrictHostKeyChecking", "no");
sessionTarget.connect();
channelTarget = (ChannelSftp) sessionTarget.openChannel("sftp");
channelTarget.connect();
System.out.println("Target Channel Connected");
} catch (JSchException e) {
System.out.println("Error Occured ======== Connection not estabilished");
log.error("Error Occured ======== Connection not estabilished", e);
} finally {
channelTarget.exit(); // Warning : dereferencing possible null pointer
channelTarget.disconnect(); // Warning : dereferencing possible null pointer
sessionTarget.disconnect(); // Warning : dereferencing possible null pointer
}
我收到了一个警告“dereferencing possible null pointer”(可能的空指针解除引用),如何解决这些警告?我应该在哪里断开我的“Session”和“Channel”连接?