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

Bug 388300

Summary: corrupted editor contents after save actions and undo
Product: [Eclipse Project] JDT Reporter: Nicolas Bros <nicolas.bros>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, srikanth_sankaran
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
stacktrace (Document does not match the AST)
none
stacktrace 2 (Overlapping text edits)
none
org.eclipse.jdt.ui.prefs (save actions with cleanups) none

Description Nicolas Bros CLA 2012-08-29 05:15:40 EDT
Steps to reproduce:
- import org.eclipse.emf.ecore (with sources) into the workspace
- enable save actions (use the attached preferences)
- open /org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/impl/EcorePackageImpl.java
- change the method body getEClass() to "return null;"
- Hit Ctrl+S and then Ctrl+Z in quick succession

You may get:
- "Document does not match the AST" (see stacktrace 1)
- or "org.eclipse.text.edits.MalformedTreeException: Overlapping text edits" (see stacktrace 2)
- Or you may get no exception, and corrupted editor contents (as indicated by compilation error markers)

If you continue to undo/redo, the editor contents become corrupted further.
Comment 1 Nicolas Bros CLA 2012-08-29 05:16:16 EDT
Created attachment 220435 [details]
stacktrace (Document does not match the AST)
Comment 2 Nicolas Bros CLA 2012-08-29 05:17:18 EDT
Created attachment 220436 [details]
stacktrace 2 (Overlapping text edits)
Comment 3 Nicolas Bros CLA 2012-08-29 05:20:44 EDT
Created attachment 220438 [details]
org.eclipse.jdt.ui.prefs (save actions with cleanups)
Comment 4 Nicolas Bros CLA 2012-08-29 05:28:06 EDT
for example, if I modify the getEClass() method to "return null;" then save, undo then undo again, I end up with:

public EClass getEClass()
{
  rrn nuleClassEClass;
}


version:
Eclipse SDK
Version: 4.2.0
Build id: I20120608-1400
Comment 5 Srikanth Sankaran CLA 2012-08-29 06:22:46 EDT
Jay, can you study this please ? Route to the other components as needed.
Since this is a data corruption issue, we should look at this soon.
Comment 6 Jay Arthanareeswaran CLA 2012-08-30 02:42:50 EDT
I don't see the MalformedTreeException, but I do end up with lot of compilation errors on the compilation unit. Subsequent saves fail with the following error message:

"A save participant caused problems.
  The save participant 'Code Clean Up' caused an exception: java.lang.IllegalArgumentException. See the error log for details."

And the log has the following stack trace:


!MESSAGE Error in JDT Core during reconcile
!STACK 0
java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2648)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:572)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:183)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2656)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1219)
	at org.eclipse.jdt.core.dom.AST.convertCompilationUnit(AST.java:246)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:206)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:89)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:788)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1247)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:126)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:108)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:89)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:87)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:151)
	at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:86)
	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:104)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:77)
	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:206)
Comment 7 Srikanth Sankaran CLA 2012-08-30 02:47:46 EDT
(In reply to comment #6)
> I don't see the MalformedTreeException, but I do end up with lot of
> compilation errors on the compilation unit. Subsequent saves fail with the
> following error message:

Is this a recent regression ? What is the earliest version that shows
the problem. The IAE could be a manifestation of the problem rather than
the problem itself ?
Comment 8 Nicolas Bros CLA 2012-08-30 02:57:31 EDT
(In reply to comment #7)
> Is this a recent regression ?

This might be related: I had experienced a similar occurrence of editor corruption almost two years ago (Bug 332653), but I never found a surefire way to reproduce it.
Comment 9 Jay Arthanareeswaran CLA 2012-08-30 05:18:07 EDT
I am able to reproduce both the error scenarios reported in comment #0.

The error is reproducible in 4.1.2 and 4.2 but none of the 3.x releases. This is because in 3.x versions, 'save' is blocking further editor operations such as undo etc.
Comment 10 Jay Arthanareeswaran CLA 2012-08-30 05:47:39 EDT
(In reply to comment #9)
> I am able to reproduce both the error scenarios reported in comment #0.
> 
> The error is reproducible in 4.1.2 and 4.2 but none of the 3.x releases.
> This is because in 3.x versions, 'save' is blocking further editor
> operations such as undo etc.

I don't know if we are supposed to allow other editor operations during a 'save'. Moving to JDT Text for investigation.
Comment 11 Dani Megert CLA 2012-08-30 07:23:32 EDT

*** This bug has been marked as a duplicate of bug 346230 ***