Bug 187877 [EFS] Null pointer exception when getting path of FileEditorInput whose file does not exist
The problem occurs in my plugin when I call FileEditorInput.getPath for a file that has been deleted on disk. This happens when you have an editor open, and then delete its project and choose the option to delete the files on disk. The built-in Eclipse editors do not run into the problem because they present a dialog asking to save or close the file and do not allow any interaction with the file. The stack trace is: java.lang.NullPointerException at org.eclipse.core.internal.filesystem.InternalFileSystemCore.getStore(InternalFileSystemCore.java:104) at org.eclipse.core.filesystem.EFS.getStore(EFS.java:350) at org.eclipse.ui.part.FileEditorInput.getPath(FileEditorInput.java:175) In FileEditorInput.getPath, the code is: final URI locationURI = file.getLocationURI(); IFileStore store = EFS.getStore(locationURI); IResources.getLocationURI is documented to return null if no URI can be determined. I believe that the code above should check for (locationURI == null) and return null. This null pointer exception occurs with Eclipse 3.3M7, but not with 3.2. A workaround for this problem is to not call IEditorInput.getPath() if IEditorInput.exists() returns false.
bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/part/FileEditorInput.java
IPath location = file.getLocation();
		if (location != null)
			return location;
		
		try {
	        final URI locationURI = file.getLocationURI();
	        if (locationURI == null)
	           return null;
	        IFileStore store = EFS.getStore(locationURI);
			
			java.io.File localFile = store.toLocalFile(EFS.NONE, null);
			
			if (localFile == null)
				localFile = store.toLocalFile(EFS.CACHE, null);
			return Path.fromOSString(localFile.getAbsolutePath());
		} catch (CoreException e) {
			
			IDEWorkbenchPlugin.log(
					"Failed to obtain file store for resource", e); 
			throw new RuntimeException(e);
		}
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return getClass().getName() + "(" + getFile().getFullPath() + ")"; 
	}
}