From 43af27a74a6ef29ae64821c586ae54644a4b4b6a Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Tue, 15 Sep 2009 21:21:37 +0000 Subject: [PATCH] [286129][api] RemoteFileException(String) violates API contract --- .../local/files/LocalFileService.java | 4 +- .../services/ssh/files/SftpFileService.java | 4 +- .../services/files/RemoteFileException.java | 45 ++++++++++++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java index 5344ae33437..b29d098ac57 100644 --- a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java @@ -43,6 +43,7 @@ * David McKnight (IBM) - [238367] [regression] Error when deleting Archive Files * David McKnight (IBM) - [280899] RSE can't open files in some directory, which give the RSEG1067 error me * Martin Oberhuber (Wind River) - [285942] Throw exception when listing a non-folder + * Martin Oberhuber (Wind River) - [286129][api] RemoteFileException(String) violates API contract *******************************************************************************/ package org.eclipse.rse.internal.services.local.files; @@ -739,7 +740,8 @@ public class LocalFileService extends AbstractFileService implements ILocalServi if (localParent.exists()) { File[] files = localParent.listFiles(fFilter); if (files == null) { - throw new RemoteFileException("Error listing: " + localParent.getAbsolutePath()); + //throw new RemoteFileException("Error listing: " + localParent.getAbsolutePath()); + throw new RemoteFileIOException(new IOException("Error listing: " + localParent.getAbsolutePath())); } return convertToHostFiles(files, type); } else { diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java index 9984eee87fe..3ce77d995e2 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java @@ -40,6 +40,7 @@ * David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService() * Martin Oberhuber (Wind River) - [274568] Dont use SftpMonitor for Streams transfer * Patrick Tassé (Ericsson) - [285226] Empty directory shown as an error message + * Martin Oberhuber (Wind River) - [286129][api] RemoteFileException(String) violates API contract *******************************************************************************/ package org.eclipse.rse.internal.services.ssh.files; @@ -556,7 +557,8 @@ public class SftpFileService extends AbstractFileService implements ISshService, SftpATTRS attrs = getChannel("SftpFileService.internalFetch: " + parentPath).stat(parentPath); //$NON-NLS-1$ if (!attrs.isDir()) { // parent was a file and not a folder - throw new RemoteFileException("Not a folder: " + parentPath); //$NON-NLS-1$ + //throw new RemoteFileException("Not a folder: " + parentPath); //$NON-NLS-1$ + throw new RemoteFileIOException(new IOException("Not a folder: " + parentPath)); //$NON-NLS-1$ } } if (filematcher.matches(fileName) || (lsEntry.getAttrs().isDir() && fileType!=IFileService.FILE_TYPE_FOLDERS)) { diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/RemoteFileException.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/RemoteFileException.java index 94ff44ee342..046d7706d3e 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/RemoteFileException.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/RemoteFileException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,18 @@ * * Contributors: * Martin Oberhuber (Wind River) - [226374] [api] Need default SystemMessageException specialisations + * Martin Oberhuber (Wind River) - [286129][api] RemoteFileException(String) violates API contract *******************************************************************************/ package org.eclipse.rse.services.files; import java.util.ResourceBundle; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.osgi.util.NLS; + +import org.eclipse.rse.internal.services.Activator; +import org.eclipse.rse.internal.services.RSEServicesMessages; +import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemRemoteMessageException; @@ -46,21 +53,32 @@ public class RemoteFileException extends SystemRemoteMessageException private static final long serialVersionUID = 1L; /** - * Constructor for RemoteFileException with an error message for getMessage() to return. + * Constructor for RemoteFileException with an error message for + * getMessage() to return. + * * @param bundle The ResourceBundle containing the error message * @param key The key to retrieve the message + * @deprecated this constructor violates the contract that all + * RemoteFileException instances must have an embedded remote + * exception for {@link #getRemoteException()} to return */ public RemoteFileException(ResourceBundle bundle, String key) { - this(getString(bundle,key), null); + this(getString(bundle, key)); } + /** - * Constructor for RemoteFileException with an error message for getMessage() to return. + * Constructor for RemoteFileException with an error message for + * getMessage() to return. + * * @param msg The fully resolved message + * @deprecated this constructor violates the contract that all + * RemoteFileException instances must have an embedded remote + * exception for {@link #getRemoteException()} to return */ public RemoteFileException(String msg) { - this(msg, null); + this(msg, new Exception(msg)); } /** * Constructor for RemoteFileException with an error message for getMessage() to return, @@ -82,15 +100,28 @@ public class RemoteFileException extends SystemRemoteMessageException public RemoteFileException(String msg, Exception remoteException) { super(msg, remoteException); + String msgTxt = RSEServicesMessages.FILEMSG_OPERATION_FAILED; + if (remoteException != null && remoteException.getMessage() != null && !remoteException.getMessage().equals(msg)) { + msg = (msg == null) ? remoteException.getMessage() : msg + ": " + remoteException.getMessage(); + } + String msgDetails = NLS.bind(RSEServicesMessages.FILEMSG_OPERATION_FAILED_DETAILS, msg); + SystemMessage myMessage = new SimpleSystemMessage(Activator.PLUGIN_ID, "RSEF1002", //$NON-NLS-1$ + IStatus.ERROR, msgTxt, msgDetails); + setSystemMessage(myMessage); } /** - * Constructor for RemoteFileException with an error message for getMessage() to return. + * Constructor for RemoteFileException with an error message for + * getMessage() to return. + * * @param msg The fully resolved message + * @deprecated this constructor violates the contract that all + * RemoteFileException instances must have an embedded remote + * exception for {@link #getRemoteException()} to return */ public RemoteFileException(SystemMessage msg) { - this(msg, null); + this(msg, new Exception(msg.getLevelOneText())); } /** * Constructor for RemoteFileException with an error message for getMessage() to return.