Skip to content

Can't format XML file with eclipseWtp #802

@exic

Description

@exic

If you are submitting a bug, please include the following:

summary of problem

Can't format XML file with eclipseWtp if it contains special constructions

gradle or maven version

Maven 3.6.3

spotless version

2.7.0

operating system and version

Linux 5.10.15-arch1-1

copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible

							<format>
								<includes>
									<include>src/**/resources/**/*.xml</include>
									<include>src/**/resources/**/*.xsd</include>
									<include>pom.xml</include>
								</includes>

								<eclipseWtp>
									<type>XML</type>
									<files>
										<file>
											see below
										</file>
									</files>
								</eclipseWtp>
							</format>

file:

eclipse.preferences.version=1
lineWidth=120

copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace

[INFO] --- spotless-maven-plugin:2.7.0:check (default-cli) @ com.company.program ---
Feb 15, 2021 12:39:27 PM com.diffplug.spotless.FormatExceptionPolicyLegacy error
SEVERE: Step 'eclipse wtp formatters - XML' found problem in 'src/test/resources/testthing.xml':
Overlapping text edits
org.eclipse.text.edits.MalformedTreeException: Overlapping text edits
	at org.eclipse.text.edits.TextEdit$InsertionComparator.compare(TextEdit.java:126)
	at org.eclipse.text.edits.TextEdit$InsertionComparator.compare(TextEdit.java:1)
	at java.util.Collections.indexedBinarySearch(Collections.java:334)
	at java.util.Collections.binarySearch(Collections.java:322)
	at org.eclipse.text.edits.TextEdit.computeInsertionIndex(TextEdit.java:799)
	at org.eclipse.text.edits.TextEdit.internalAdd(TextEdit.java:784)
	at org.eclipse.text.edits.TextEdit.addChild(TextEdit.java:340)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.collapseSpaces(DefaultXMLPartitionFormatter.java:106)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatWithinEndTag(DefaultXMLPartitionFormatter.java:861)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatEndTag(DefaultXMLPartitionFormatter.java:437)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:629)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:462)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:578)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:462)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:578)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:462)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatStartTag(DefaultXMLPartitionFormatter.java:578)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatRegion(DefaultXMLPartitionFormatter.java:462)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.formatSiblings(DefaultXMLPartitionFormatter.java:505)
	at org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter.format(DefaultXMLPartitionFormatter.java:218)
	at com.diffplug.spotless.extra.eclipse.wtp.EclipseXmlFormatterStepImpl.format(EclipseXmlFormatterStepImpl.java:135)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.lambda$applyWithFile$2(EclipseWtpFormatterStep.java:79)
	at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:154)
	at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
	at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
	at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:201)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:188)
	at com.diffplug.spotless.maven.SpotlessCheckMojo.process(SpotlessCheckMojo.java:52)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:146)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:137)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:190)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:186)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

I was able to boil testthing.xml down to:

<x>&quot;
 </x>

I managed to reproduce on current main branch using:

diff --git plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java plugin-maven/src/test/java/com/diffplug/spotless/maven/generic>
index 5a1a5eb0..bfe3c45e 100644
--- plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java
+++ plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/EclipseWtpTest.java
@@ -31,8 +31,8 @@ public class EclipseWtpTest extends MavenIntegrationHarness {
    }
 
    private void runTest() throws Exception {
-       String notFormatted = "<a><b>   c</b></a>";
-       String formatted = "<a>\n\t<b> c</b>\n</a>";
+       String notFormatted = "<a><b>   &quot;\n </b></a>";
+       String formatted = "<a>\n\t<b> &quot;</b>\n</a>";
        //writePomWithFormatSteps includes java. WTP does not care about file extensions.
        setFile("src/main/java/test.java").toContent(notFormatted);
        mavenRunner().withArguments("spotless:apply").runNoError();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions