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

Bug 353025

Summary: [implementation] NPE during Save when "Refresh on Access" enabled
Product: [Eclipse Project] Platform Reporter: Martin Oberhuber <mober.at+eclipse>
Component: TextAssignee: Dani Megert <daniel_megert>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: antonel.pazargic, daniel_megert, d_a_carver, esteban.dugueperoux, jamesblackburn+eclipse, jeremy, kkazmierczyk+eclipse, lance.eason, lars.geyer-blaumeiser, loskutov, malaperle, markus.kell.r, mober.at+eclipse, pwebster, remy.suen, Szymon.Brandys, wbeckwith, win32pro, xavier.mehaut, yevshif
Version: 3.7Keywords: investigate
Target Milestone: 3.8 M7   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 14867    
Bug Blocks:    

Description Martin Oberhuber CLA 2011-07-25 13:44:53 EDT
Build ID: Eclipse 3.7 (Indigo)

When the new "Refresh on Access" Preference from bug 14867 is on, data loss can occur in the following scenario:

1. Create a General Project
2. Create file "sample.txt", save but keep editor open.
3. Outside Eclipse, delete or rename sample.txt
4. Switch back to Eclipse --> See following dialog:

   "The file proj/sample.txt has been deleted or is not accessible. Do you
    want to save your changes or close the editor without saving?"

5. Press "Save" --> Nothing happens, except NPE printed to errorlog
   (see below). That is, the file which I've just been editing, is lost and
   gone. 

The problem seems to be that due to the "Refresh on Access", the EditorInput is deleted before Eclipse has a chance to save the file. The issue does not occur when the editor is dirty, or when the "Refresh on Access" preference is off.

This issue is particularly concerning in a ClearCase dynamic view, when I'm editing a file while a different user performs renames or deletes that file. Recovering my data may be possible (since the editor was not dirty), but the behavior is unexpected and recovery likely nontrivial.

The NPE:

Caused by: java.lang.NullPointerException
	at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.performSaveAs(AbstractDecoratedTextEditor.java:1552)
	at org.eclipse.ui.texteditor.AbstractTextEditor.handleEditorInputChanged(AbstractTextEditor.java:4737)
	at org.eclipse.ui.texteditor.StatusTextEditor.handleEditorInputChanged(StatusTextEditor.java:267)
	at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.handleEditorInputChanged(AbstractDecoratedTextEditor.java:1474)
	at org.eclipse.ui.texteditor.AbstractTextEditor.sanityCheckState(AbstractTextEditor.java:4887)
	at org.eclipse.ui.texteditor.StatusTextEditor.sanityCheckState(StatusTextEditor.java:257)
	at org.eclipse.ui.texteditor.AbstractTextEditor.safelySanityCheckState(AbstractTextEditor.java:4865)
	at org.eclipse.ui.texteditor.AbstractTextEditor$ActivationListener.handleActivation(AbstractTextEditor.java:984)
	at org.eclipse.ui.texteditor.AbstractTextEditor$ActivationListener.access$0(AbstractTextEditor.java:977)
	at org.eclipse.ui.texteditor.AbstractTextEditor$10.run(AbstractTextEditor.java:1005)
Comment 1 Dani Megert CLA 2011-07-26 03:35:56 EDT
>3. Outside Eclipse, delete or rename sample.txt

Mmh, I'd rather say it's data loss if the file is still there after you explicitly deleted it ;-).