From 38b35acc9bea8e06827ea255869dbc1c7ae2cd62 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Fri, 25 Apr 2008 21:10:57 +0000 Subject: [PATCH] [225747] [dstore] Trying to connect to an "Offline" system throws an NPE --- .../internal/core/model/SystemRegistry.java | 9 +- .../resources/SystemEditableRemoteFile.java | 19 ++-- .../ui/resources/SystemTempFileListener.java | 4 +- .../ui/view/SystemViewRemoteFileAdapter.java | 16 +-- .../core/subsystems/RemoteFileSubSystem.java | 3 +- .../ui/actions/SystemWorkOfflineAction.java | 31 ++++-- .../rse/internal/ui/view/SystemViewPart.java | 102 +++++++++--------- .../ui/operations/SystemFetchOperation.java | 4 + .../rse/core/subsystems/SubSystem.java | 17 +-- 9 files changed, 121 insertions(+), 84 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/SystemRegistry.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/SystemRegistry.java index db79611bd58..eec8a842960 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/SystemRegistry.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/SystemRegistry.java @@ -49,6 +49,7 @@ * David Dykstal (IBM) - [200735][Persistence] Delete a profile that contains a connection and restart, profile is back without connections * David Dykstal (IBM) - [168976][api] move ISystemNewConnectionWizardPage from core to UI * Martin Oberhuber (Wind River) - [228774] Improve ElementComparer Performance + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE ********************************************************************************/ package org.eclipse.rse.internal.core.model; @@ -2757,7 +2758,13 @@ public class SystemRegistry implements ISystemRegistry { ISystemFilterReference ref = (ISystemFilterReference)remoteResource; ISubSystem ss = ref.getSubSystem(); - remoteResource = ss.getTargetForFilter(ref); + if (!ss.isOffline()){ + remoteResource = ss.getTargetForFilter(ref); + } + else { + return null; + } + IRemoteObjectIdentifier rid = getRemoteObjectIdentifier(remoteResource); if (rid == null) return null; diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java index 90b58289233..15a6c3ef055 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java @@ -30,6 +30,7 @@ * David McKnight (IBM) - [222406] Need to be able to override local encoding * David McKnight (IBM) - [224377] "open with" menu does not have "other" option * Kevin Doyle (IBM) - [224162] SystemEditableRemoteFile.saveAs does not work because FileServiceSubSytem.upload does invalid check + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.files.ui.resources; @@ -1574,14 +1575,16 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP // get fresh remote file object remoteFile.markStale(true); // make sure we get the latest remote file (with proper permissions and all) - try - { - remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath(), new NullProgressMonitor()); - } - catch (Exception e) - { - SystemMessageDialog.displayExceptionMessage(SystemMessageDialog.getDefaultShell(), e); - return; + if (!remoteFile.getParentRemoteFileSubSystem().isOffline()){ + try + { + remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath(), new NullProgressMonitor()); + } + catch (Exception e) + { + SystemMessageDialog.displayExceptionMessage(SystemMessageDialog.getDefaultShell(), e); + return; + } } boolean readOnly = !remoteFile.canWrite(); ResourceAttributes attr = file.getResourceAttributes(); diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemTempFileListener.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemTempFileListener.java index 1fcdfba4a80..4d7a08570ca 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemTempFileListener.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemTempFileListener.java @@ -21,6 +21,7 @@ * Martin Oberhuber (Wind River) - [199573] Fix potential threading issues in SystemTempFileListener * David McKnight (IBM) - [205297] Editor upload should not be on main thread * David McKnight (IBM) - [216252] [api][nls] Resource Strings specific to subsystems should be moved from rse.ui into files.ui / shells.ui / processes.ui where possible + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.files.ui.resources; @@ -611,7 +612,7 @@ public abstract class SystemTempFileListener implements IResourceChangeListener } // attempt the remote file synchronization - if (doesHandle(fs)) + if (doesHandle(fs) && !fs.isOffline()) { // see if we're connected try @@ -632,7 +633,6 @@ public abstract class SystemTempFileListener implements IResourceChangeListener properties.setDirty(true); return; } - doResourceSynchronization(fs, file, uploadPath, monitor); } } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java index b05d5550a77..04ae3aa932b 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java @@ -50,6 +50,7 @@ * Xuan Chen (IBM) - [223126] [api][breaking] Remove API related to User Actions in RSE Core/UI * Rupen Mardirossian (IBM) - [210682] Copy collisions will use SystemCopyDialog now instead of renameDialog when there is a copy collision within the same connection * David McKnight (IBM) - [224377] "open with" menu does not have "other" option + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.internal.files.ui.view; @@ -3285,13 +3286,14 @@ public class SystemViewRemoteFileAdapter // get updated remoteFile so we get the current remote timestamp //remoteFile.markStale(true); IRemoteFileSubSystem subsystem = remoteFile.getParentRemoteFileSubSystem(); - try - { - remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath(), new NullProgressMonitor()); - } - catch (Exception e) - { - + if (!subsystem.isOffline()){ // only do this check when online..if offline we assume the temp file is okay + try + { + remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath(), new NullProgressMonitor()); + } + catch (Exception e) + { + } } // get the remote modified stamp diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java index b90d8b1639b..341aa199fc6 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java @@ -27,6 +27,7 @@ * David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared * Martin Oberhuber (Wind River) - [218304] Improve deferred adapter loading * Martin Oberhuber (Wind River) - [226574][api] Add ISubSystemConfiguration#supportsEncoding() + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.subsystems.files.core.subsystems; @@ -332,7 +333,7 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi if (container == null) return false; - if (container.equals(".")) //$NON-NLS-1$ + if (container.equals(".") && !isOffline()) //$NON-NLS-1$ { try { diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemWorkOfflineAction.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemWorkOfflineAction.java index 9c0c8f8937d..de695f0cc90 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemWorkOfflineAction.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/SystemWorkOfflineAction.java @@ -14,10 +14,15 @@ * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry - ********************************************************************************/ + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE +*******************************************************************************/ package org.eclipse.rse.internal.ui.actions; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IHost; @@ -68,8 +73,8 @@ public class SystemWorkOfflineAction extends SystemBaseAction */ public void run() { - IHost conn = (IHost)getFirstSelection(); - ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry(); + final IHost conn = (IHost)getFirstSelection(); + final ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry(); if (conn.isOffline()) { @@ -103,17 +108,25 @@ public class SystemWorkOfflineAction extends SystemBaseAction } } - // check that everything was disconnedted okay and this is not the local connection - if(sr.isAnySubSystemConnected(conn) && !conn.getSystemType().isLocal()) + Job job = new Job("Ensure Disconnected") { - // backout changes, likely because user cancelled the disconnect - setChecked(false); - sr.setHostOffline(conn, false); - } + public IStatus run(IProgressMonitor monitor){ + // check that everything was disconnedted okay and this is not the local connection + if(sr.isAnySubSystemConnected(conn) && !conn.getSystemType().isLocal()) + { + // backout changes, likely because user cancelled the disconnect + setChecked(false); + sr.setHostOffline(conn, false); + } + return Status.OK_STATUS; + } + }; + job.schedule(); } } + /* (non-Javadoc) * @see org.eclipse.rse.core.ui.actions.SystemBaseAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) */ diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemViewPart.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemViewPart.java index 8f62ebf4c95..6ae8de3d505 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemViewPart.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemViewPart.java @@ -29,6 +29,7 @@ * David McKnight (IBM) - [199424] restoring memento state asynchronously * David McKnight (IBM) - [187711] Link with Editor handled by extension * David Dykstal (IBM) - [226728] NPE during init with clean workspace + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.internal.ui.view; @@ -131,7 +132,6 @@ import org.eclipse.ui.part.ISetSelectionTarget; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.views.framelist.FrameList; - /** * This is the desktop view wrapper of the System View viewer. */ @@ -1538,68 +1538,72 @@ public class SystemViewPart { ss.getCacheManager().setRestoreFromMemento(true); } - - String path = robject.name; - ISystemFilterReference fref = robject.fRef; - - try - { - Object actualObject = ss.getObjectWithAbsoluteName(path, monitor); + + if (!ss.isOffline()){ + String path = robject.name; + ISystemFilterReference fref = robject.fRef; - if (actualObject instanceof IAdaptable) + try { - // get the adapter - ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)actualObject).getAdapter(ISystemViewElementAdapter.class); + Object actualObject = ss.getObjectWithAbsoluteName(path, monitor); - // get the context - ContextObject contextObject = new ContextObject(actualObject, ss, fref); + if (actualObject instanceof IAdaptable) + { + // get the adapter + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)actualObject).getAdapter(ISystemViewElementAdapter.class); + + // get the context + ContextObject contextObject = new ContextObject(actualObject, ss, fref); + + // get the children + Object[] children = adapter.getChildren(contextObject, monitor); - // get the children - Object[] children = adapter.getChildren(contextObject, monitor); - - ShowRestoredRemoteObject showRunnable = new ShowRestoredRemoteObject(actualObject, children); - Display.getDefault().asyncExec(showRunnable); + ShowRestoredRemoteObject showRunnable = new ShowRestoredRemoteObject(actualObject, children); + Display.getDefault().asyncExec(showRunnable); + } + + } + catch (Exception e) + { + // unexpected } + // yantzi: artemis 6.0: reset restore from memento flag + if (ss != null && ss.supportsCaching()) + { + ss.getCacheManager().setRestoreFromMemento(false); + } } - catch (Exception e) - { - // unexpected - } - - // yantzi: artemis 6.0: reset restore from memento flag - if (ss != null && ss.supportsCaching()) - { - ss.getCacheManager().setRestoreFromMemento(false); - } } else if (object instanceof ISystemFilterReference) { ISystemFilterReference fref = (ISystemFilterReference)object; ISubSystem ss = fref.getSubSystem(); - if (!ss.isConnected()){ - try + if (!ss.isOffline()){ + if (!ss.isConnected()){ + try + { + ss.connect(monitor, false); + } + catch (Exception e){ + return Status.CANCEL_STATUS; + } + } + if (ss.isConnected()) { - ss.connect(monitor, false); - } - catch (Exception e){ - return Status.CANCEL_STATUS; - } + // get the adapter + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)object).getAdapter(ISystemViewElementAdapter.class); + + // get the context + ContextObject contextObject = new ContextObject(fref, ss, fref); + + // get the children + Object[] children = adapter.getChildren(contextObject, monitor); + + ShowRestoredRemoteObject showRunnable = new ShowRestoredRemoteObject(fref, children); + Display.getDefault().asyncExec(showRunnable); + } } - if (ss.isConnected()) - { - // get the adapter - ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)object).getAdapter(ISystemViewElementAdapter.class); - - // get the context - ContextObject contextObject = new ContextObject(fref, ss, fref); - - // get the children - Object[] children = adapter.getChildren(contextObject, monitor); - - ShowRestoredRemoteObject showRunnable = new ShowRestoredRemoteObject(fref, children); - Display.getDefault().asyncExec(showRunnable); - } } } boolean restoreFromCache = RSEUIPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.RESTORE_STATE_FROM_CACHE); diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/operations/SystemFetchOperation.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/operations/SystemFetchOperation.java index c9860d5267f..564d3b6c074 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/operations/SystemFetchOperation.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/operations/SystemFetchOperation.java @@ -16,6 +16,7 @@ * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry * Martin Oberhuber (Wind River) - [189272] exception when canceling ssh connect * David Dykstal (IBM) - [189483] add notification when canceling password prompting + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE *******************************************************************************/ package org.eclipse.rse.ui.operations; @@ -229,6 +230,9 @@ public class SystemFetchOperation extends JobChangeAdapter implements IRunnableW { ss = (SubSystem)_adapter.getSubSystem(_remoteObject); } + if (ss.isOffline() ){ + return; + } synchronized (ss.getConnectorService()) { if (!ss.isConnected()) diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java index 7aded9a9d99..19b1aadb0d9 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java @@ -37,6 +37,7 @@ * David Dykstal (IBM) - [225089][ssh][shells][api] Canceling connection leads to exception * Martin Oberhuber (Wind River) - [218304] Improve deferred adapter loading * Martin Oberhuber (Wind River) - [190231] Prepare API for UI/Non-UI Splitting + * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE ********************************************************************************/ package org.eclipse.rse.core.subsystems; @@ -1696,14 +1697,16 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider msg = SubSystemConfiguration.getConnectingMessage(getHostName(), getConnectorService().getPort()); SystemBasePlugin.logInfo(msg); - if (!implicitConnect(true, mon, msg, totalWorkUnits)){ - String msgTxt = NLS.bind(CommonMessages.MSG_CONNECT_FAILED, getHostName()); - throw new Exception(msgTxt); - } - internalConnect(mon); + if (!isOffline()){ + if (!implicitConnect(true, mon, msg, totalWorkUnits)){ + String msgTxt = NLS.bind(CommonMessages.MSG_CONNECT_FAILED, getHostName()); + throw new Exception(msgTxt); + } + internalConnect(mon); - ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); - registry.connectedStatusChange(_ss, true, false); + ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); + registry.connectedStatusChange(_ss, true, false); + } } }