From 2848dc80ff2dcaa078045a0b19efe080fa444d82 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 11 May 2007 11:40:52 +0000 Subject: [PATCH] [175328] NPE on SSH Disconnect --- .../ssh/SshConnectorService.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java index 46309fcb594..45f498e291d 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java @@ -120,8 +120,7 @@ public class SshConnectorService extends StandardConnectorService implements ISs Activator.trace("SshConnectorService.connected"); //$NON-NLS-1$ } catch (JSchException e) { Activator.trace("SshConnectorService.connect failed: "+e.toString()); //$NON-NLS-1$ - if (session.isConnected()) - session.disconnect(); + sessionDisconnect(); if(e.toString().indexOf("Auth cancel")>=0) { //$NON-NLS-1$ throw new OperationCanceledException(); } @@ -132,6 +131,23 @@ public class SshConnectorService extends StandardConnectorService implements ISs notifyConnection(); } + /** + * Disconnect the ssh session. + * Synchronized in order to avoid NPE's from Jsch when called + * quickly in succession. + */ + private synchronized void sessionDisconnect() { + Activator.trace("SshConnectorService.sessionDisconnect"); //$NON-NLS-1$ + try { + if (session.isConnected()) + session.disconnect(); + } catch(Exception e) { + //Bug 175328: NPE on disconnect shown in UI + //This is a non-critical exception so print only in debug mode + if (Activator.isTracingOn()) e.printStackTrace(); + } + } + protected void internalDisconnect(IProgressMonitor monitor) throws Exception { //TODO Will services like the sftp service be disconnected too? Or notified? @@ -151,10 +167,7 @@ public class SshConnectorService extends StandardConnectorService implements ISs // Fire comm event to signal state about to change fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT); } - - if (session.isConnected()) { - session.disconnect(); - } + sessionDisconnect(); // Fire comm event to signal state changed notifyDisconnection();