1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-14 20:45:22 +02:00

[203490] Fix NPE in SftpService.getUserHome()

This commit is contained in:
Martin Oberhuber 2007-09-26 21:14:52 +00:00
parent 04da14a895
commit eec09ac96e
2 changed files with 17 additions and 7 deletions

View file

@ -60,6 +60,7 @@
* Javier Montalvo Orus (Symbian) - [199243] Renaming a file in an FTP-based EFS folder hangs all of Eclipse * Javier Montalvo Orus (Symbian) - [199243] Renaming a file in an FTP-based EFS folder hangs all of Eclipse
* Martin Oberhuber (Wind River) - [203306] Fix Deadlock comparing two files on FTP * Martin Oberhuber (Wind River) - [203306] Fix Deadlock comparing two files on FTP
* Martin Oberhuber (Wind River) - [204669] Fix ftp path concatenation on systems using backslash separator * Martin Oberhuber (Wind River) - [204669] Fix ftp path concatenation on systems using backslash separator
* Martin Oberhuber (Wind River) - [203490] Fix NPE in FTPService.getUserHome()
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp; package org.eclipse.rse.internal.services.files.ftp;
@ -888,9 +889,15 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
*/ */
public IHostFile getUserHome() public IHostFile getUserHome()
{ {
if (_userHome==null) {
//As per bug 204710, this may be called before we are connected.
//Returning null in this case is safest, see also SftpFileService.
return null;
}
return new FTPHostFile("",_userHome,true,true,0,0,true); //$NON-NLS-1$ return new FTPHostFile("",_userHome,true,true,0,0,true); //$NON-NLS-1$
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.rse.services.files.IFileService#getRoots(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.rse.services.files.IFileService#getRoots(org.eclipse.core.runtime.IProgressMonitor)

View file

@ -64,7 +64,7 @@ import org.eclipse.rse.services.files.RemoteFileSecurityException;
public class SftpFileService extends AbstractFileService implements IFileService, ISshService public class SftpFileService extends AbstractFileService implements IFileService, ISshService
{ {
private class SftpBufferedInputStream extends BufferedInputStream { private static class SftpBufferedInputStream extends BufferedInputStream {
private ChannelSftp channel; private ChannelSftp channel;
@ -99,7 +99,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
} }
} }
private class SftpBufferedOutputStream extends BufferedOutputStream { private static class SftpBufferedOutputStream extends BufferedOutputStream {
private ChannelSftp channel; private ChannelSftp channel;
@ -574,7 +574,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
} }
public IHostFile getUserHome() { public IHostFile getUserHome() {
//TODO Assert: this is only called after we are connected //As per bug 204710, this may be called before we are connected
if (fUserHome!=null) { if (fUserHome!=null) {
int lastSlash = fUserHome.lastIndexOf('/'); int lastSlash = fUserHome.lastIndexOf('/');
String name = fUserHome.substring(lastSlash + 1); String name = fUserHome.substring(lastSlash + 1);
@ -582,12 +582,15 @@ public class SftpFileService extends AbstractFileService implements IFileService
try { try {
return getFile(parent, name, null); return getFile(parent, name, null);
} catch(SystemMessageException e) { } catch(SystemMessageException e) {
//Error getting user home -> return a default below //Error getting user home -> return a handle
//Returning the home path as a Root is the safest we can do, since it will
//let users know what the home path is, and the "My Home" filter will be
//set to correct target. See also bug 204710.
return new SftpHostFile("", fUserHome, true, true, false, 0, 0); //$NON-NLS-1$
} }
} }
//Could not determine user home //Bug 203490, bug 204710: Could not determine user home
//return new SftpHostFile(".",".",true,false,false,0,0); //$NON-NLS-1$ //$NON-NLS-2$ return null;
return new SftpHostFile("/", "/", true, true, false, 0, 0); //$NON-NLS-1$ //$NON-NLS-2$
} }
public IHostFile[] getRoots(IProgressMonitor monitor) { public IHostFile[] getRoots(IProgressMonitor monitor) {