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
* Adapter for making a file resource a suitable input for an editor.
 * <p>
 * This class may be instantiated; it is not intended to be subclassed.
 * </p>
 */
public class FileEditorInput implements IFileEditorInput, IPathEditorInput, IURIEditorInput,
		IPersistableElement {
	private IFile file;
	/**
	 * Creates an editor input based of the given file resource.
	 *
	 * @param file the file resource
	 */
	public FileEditorInput(IFile file) {
		if (file == null) {
			throw new IllegalArgumentException();
		}
		this.file = file;
	}
	/* (non-Javadoc)
	 * Method declared on Object.
	 */
	public int hashCode() {
		return file.hashCode();
	}
	/* (non-Javadoc)
	 * Method declared on Object.
	 *
	 * The <code>FileEditorInput</code> implementation of this <code>Object</code>
	 * method bases the equality of two <code>FileEditorInput</code> objects on the