Bug 237592 - [formatter] MalformedTreeException when formatting edited lines
Summary: [formatter] MalformedTreeException when formatting edited lines
Status: VERIFIED DUPLICATE of bug 234583
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.5 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-18 03:57 EDT by Benno Baumgartner CLA
Modified: 2008-09-15 09:14 EDT (History)
4 users (show)

See Also:


Attachments
screen shot (15.43 KB, image/png)
2008-06-18 03:57 EDT, Benno Baumgartner CLA
no flags Details
snippet class (128 bytes, text/x-java)
2008-06-18 05:32 EDT, Benno Baumgartner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2008-06-18 03:57:20 EDT
Created attachment 105260 [details]
screen shot

I20080613-2000

1. Enable 'Format edited lines' on save with eclipse built-in profile
2. Given the CU on the left side of the picture (editor not dirty)
3. change the CU as indicated on the right side of the picture
4. Save
Is:
 Error dialog 'Save participant caused an exception':

org.eclipse.text.edits.MalformedTreeException: Range of child edit lies outside of parent edit
	at org.eclipse.text.edits.TextEdit.internalAdd(TextEdit.java:776)
	at org.eclipse.text.edits.TextEdit.addChild(TextEdit.java:335)
	at org.eclipse.jdt.internal.formatter.Scribe.getRootEdit(Scribe.java:837)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:806)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatCompilationUnit(DefaultCodeFormatter.java:331)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:203)
	at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:323)
	at org.eclipse.jdt.internal.corext.fix.CodeFormatFix.createCleanUp(CodeFormatFix.java:71)
	at org.eclipse.jdt.internal.ui.fix.CodeFormatCleanUp.createFix(CodeFormatCleanUp.java:62)
	at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.calculateChange(CleanUpRefactoring.java:782)
	at org.eclipse.jdt.internal.corext.fix.CleanUpPostSaveListener.saved(CleanUpPostSaveListener.java:263)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider$5.run(CompilationUnitDocumentProvider.java:1539)
Comment 1 Frederic Fusier CLA 2008-06-18 05:14:55 EDT
Could you attach the CU? It will be easier for me to reproduce, thx...
Comment 2 Frederic Fusier CLA 2008-06-18 05:30:11 EDT
(In reply to comment #1)
> Could you attach the CU? It will be easier for me to reproduce, thx...
> 
Forget it I created it manually...

Note that this is not a regression introduced  by the new comment formatter as I was able to reproduce the failure using 3.4M6
Comment 3 Benno Baumgartner CLA 2008-06-18 05:32:09 EDT
Created attachment 105265 [details]
snippet class
Comment 4 Frederic Fusier CLA 2008-06-18 05:32:53 EDT
(In reply to comment #3)
> Created an attachment (id=105265) [details]
> snippet class
> 
Thanks :-)

Just a question why do you consider it as major? The exception just makes the
formatting failed, the file changed are well save after the action. IMO, this
bug would have a 'normal' severity...
Comment 5 Benno Baumgartner CLA 2008-06-18 05:40:18 EDT
(In reply to comment #4)
> Just a question why do you consider it as major? The exception just makes the
> formatting failed, the file changed are well save after the action. IMO, this
> bug would have a 'normal' severity...

Maybe it's not major, but an ugly error dialog pops up on save. I guess the severity does not matter too much because IMHO it's a must fix, maybe even for 3.4.1?

Comment 6 Philipe Mulet CLA 2008-06-18 06:34:16 EDT
I agree with 3.4.1 target.
Comment 7 Frederic Fusier CLA 2008-06-18 06:44:48 EDT
I suspect that this issue might be a consequence of bug 234583...
Comment 8 Frederic Fusier CLA 2008-06-19 10:57:58 EDT
My assumption was correct. There's a bug in the current implemented regions adapting. The first given region is adapted from [64+3] to [57+49] which overlaps the second given region [84+2] and produces the MalformedTreeException...

So, we cannot consider it as a duplicate but this bug will be fixed at the same time than bug 234583.
Comment 9 Frederic Fusier CLA 2008-07-08 11:45:59 EDT
(In reply to comment #8)
> My assumption was correct. There's a bug in the current implemented regions
> adapting. The first given region is adapted from [64+3] to [57+49] which
> overlaps the second given region [84+2] and produces the
> MalformedTreeException...
> 
> So, we cannot consider it as a duplicate but this bug will be fixed at the same
> time than bug 234583.
> 
=> set it as duplicate because fix for bug 234583 will fix this one...


*** This bug has been marked as a duplicate of bug 234583 ***
Comment 10 Olivier Thomann CLA 2008-08-28 12:20:07 EDT
Verified for 3.4.1 using M20080827-2000
Comment 11 Olivier Thomann CLA 2008-08-28 12:21:30 EDT
I could not reproduce using M20080827-2000. Did I miss something ?
Comment 12 Olivier Thomann CLA 2008-08-28 12:23:33 EDT
dup of bug 234583

*** This bug has been marked as a duplicate of bug 234583 ***
Comment 13 Frederic Fusier CLA 2008-08-29 05:31:57 EDT
(In reply to comment #11)
> I could not reproduce using M20080827-2000. Did I miss something ?
> 
I was able to reproduce the MalformedTreeException both on 3.4.0 and 3.4.1 (M20080827-2000). You must strictly follow the steps given on comment 0.
Comment 14 Frederic Fusier CLA 2008-08-29 07:54:53 EDT
As the fix of the original bug will go into HEAD stream only, I'll open another bug against JDT/Text not to report the MalformedTreeException but only log it.

As there's no editor crash and the file is well saved, there's no reason to worry the user with a dialog about this exception. If it notice that his changes are not formatted, then we would advice to have a look in the log to see if there's such an exception it...
Comment 15 Frederic Fusier CLA 2008-08-29 09:05:41 EDT
If bug 245688 was fixed in R3_4_maintenance stream, then this failure wouldn't hurt the user too much while using 3.4.2...
Comment 16 David Audel CLA 2008-09-15 09:14:33 EDT
Verified for 3.5M2 using I20080914-2000