Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 187877

Summary: [EFS] Null pointer exception when getting path of FileEditorInput whose file does not exist
Product: [Eclipse Project] Platform Reporter: Gregory Dow <dow>
Component: IDEAssignee: Tod Creasey <Tod_Creasey>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: john.arthorne, n.a.edgar
Version: 3.3Flags: Tod_Creasey: review? (john.arthorne)
Target Milestone: 3.4   
Hardware: All   
OS: All   
Whiteboard: hasPatch
Bug Depends on:    
Bug Blocks: 188448, 199770    
Attachments:
Description Flags
Patch none

Description Gregory Dow CLA 2007-05-18 14:15:58 EDT
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.
Comment 1 Tod Creasey CLA 2007-05-22 13:50:11 EDT
Adding John to help with this - I am not sure that there is anything we can do in the 3.3 timeframe - we should fail more gracefully with this
Comment 2 John Arthorne CLA 2007-05-22 15:05:21 EDT
I suggest reverting to the 3.2 behaviour in this case, and return null from the getPath method.

if (locationURI == null)
  return null;

Many callers do check for null when calling getPath, so they will be better off. The same situation occurs for FileEditorInput.getURI(), which also returns null in this case. Ideally IPathEditorInput and IURIEditorInput should specify the behaviour in this case - perhaps something to revisit after 3.3.
Comment 3 Tod Creasey CLA 2007-05-22 15:17:02 EDT
This was my gut feeling as well but my concern was that null was never expressed as a valid value for IPathEditorInput#getPath.

Would clarifying the javadoc be considered an API change?
Comment 4 Tod Creasey CLA 2007-05-22 15:29:01 EDT
Bug 188448 has been logged for the javadoc update which we will have to wait until 3.4 for. 

I agree with John's assessment - honouring he 3.2 behaviour of returning null in that case is the way to go.
Comment 5 Tod Creasey CLA 2007-05-22 16:25:13 EDT
Created attachment 68207 [details]
Patch

Patch to emulate the 3.0 behaviour. Note we need 2 null checks in the end.
Comment 6 Tod Creasey CLA 2007-06-28 15:45:14 EDT
Fix released for build >20070628
Comment 7 John Arthorne CLA 2007-06-28 17:17:12 EDT
*** Bug 194819 has been marked as a duplicate of this bug. ***
Comment 8 Tod Creasey CLA 2007-08-07 14:41:59 EDT
Verified in  I20070807-0010
Comment 9 Tod Creasey CLA 2007-08-13 11:48:44 EDT
Note that this solution has been integrated into the solution for Bug 199770.