Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353451 - The XML formatter aborts formatting for construct
Summary: The XML formatter aborts formatting for construct
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-30 00:33 EDT by Tor Norbye CLA
Modified: 2011-09-15 01:54 EDT (History)
2 users (show)

See Also:
thatnitind: review+


Attachments
Screenshot showing my formatting settings (38.55 KB, image/png)
2011-08-09 16:45 EDT, Tor Norbye CLA
no flags Details
patch (6.42 KB, patch)
2011-08-12 16:54 EDT, Nick Sandonato CLA
no flags Details | Diff
patch with unit test (9.21 KB, patch)
2011-08-12 17:02 EDT, Nick Sandonato CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Norbye CLA 2011-07-30 00:33:44 EDT
When formatting the following XML document the formatter throws an exception and aborts.

(This nonsensical document is obviously boiled down from a much larger document)

<?xml version="1.0" encoding="utf-8"?>
<a>
&lt;
<!-- b -->
</a>

"Format" did not complete normally.  Please see the log for more information.
Overlapping text edits

(the log does not contain a stacktrace... but it's 100% reproducible for me.)

Eclipse 3.7:
eclipse.buildId=I20110613-1736
java.version=1.6.0_26
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -product org.eclipse.platform.ide
Command-line arguments:  -product org.eclipse.platform.ide -data {omitted} -dev {omitted} -os macosx -ws cocoa -arch x86_64 -consoleLog
Comment 1 Nick Sandonato CLA 2011-08-09 16:10:52 EDT
Hi Tor,

Thanks for your bug report. I haven't been able to reproduce this myself. I think I might need some more info.

Have you changed any of the formatting settings for XML files (Preferences > XML > XML Files > Editor)?
Wer any formatting characters lost when pasting the example into the bug description (if so, would it be possible to attach the example file to the defect to preserve original formatting)?
Comment 2 Tor Norbye CLA 2011-08-09 16:45:02 EDT
Created attachment 201187 [details]
Screenshot showing my formatting settings

Yes, I have customized the XML formatting settings. 

The bug didn't reproduce with the settings I actually use, which are the exact settings shown in the screenshot except for Format Comments and Align Final Bracket, but when I added those two settings to my formatting settings then the bug starts reproducing. (Version: Indigo Release, Build id: 20110615-0604).

I paste -exactly- the string shown in the bug description which begins with "<?xml" and ends with "</a>" and it's all shown in the editor; I then hit Ctrl-Shift-F (on Mac) and that opens the "Problem Occurred" dialog with the formatting exception which seems to point to the comment formatting as the culprit:

org.eclipse.text.edits.MalformedTreeException: Overlapping text edits
	at org.eclipse.text.edits.TextEdit$InsertionComparator.compare(TextEdit.java:121)
	at java.util.Collections.indexedBinarySearch(Collections.java:319)
	at java.util.Collections.binarySearch(Collections.java:307)
	at org.eclipse.text.edits.TextEdit.computeInsertionIndex(TextEdit.java:796)
	at org.eclipse.text.edits.TextEdit.internalAdd(TextEdit.java:781)
	at org.eclipse.text.edits.TextEdit.addChild(TextEdit.java:335)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.indentIfNotAlreadyIndented(DefaultXMLPartitionFormatter.java:1247)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatCommentStart(DefaultXMLPartitionFormatter.java:1127)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatComment(DefaultXMLPartitionFormatter.java:1018)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:457)
Comment 3 Nick Sandonato CLA 2011-08-09 17:05:52 EDT
Thanks, Tor. I was able to reproduce with your example and by modifying the formatting preferences. It looks like a combination of "Format comments" and "Clear all blank lines" is causing the problem.
Comment 4 Nick Sandonato CLA 2011-08-12 16:54:22 EDT
Created attachment 201438 [details]
patch

The problem was the formatter had two contributions to formatting the trailing whitespace in the text region containing the entity reference.
Comment 5 Nick Sandonato CLA 2011-08-12 17:02:16 EDT
Created attachment 201441 [details]
patch with unit test

Previous attachment was missing my unit test.
Comment 6 Nick Sandonato CLA 2011-08-24 17:00:19 EDT
Code released for 3_3_maintenance and HEAD.
Comment 7 Lin ZuXiong CLA 2011-09-15 01:53:26 EDT
I have it , too!
Comment 8 Lin ZuXiong CLA 2011-09-15 01:54:03 EDT
(In reply to comment #7)
> I have it , too!

eclipse-jee-indigo-win32-x86_64