Repository: diffplug/spotless (2025-06-23T11:09:52Z)

Issue:
avoid `empty body`  warnings emposed by default activation of `expandEmptyElements`
It would be nice to avoid `empty body` warnings emposed by default activation of `expandEmptyElements`, by disabling default value for this property.


make `false`:

https://github.com/diffplug/spotless/blob/2cc8c04ad168641c9cbd6fa99d30e3c7dfdb3b68/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java#L30

need:
```xml
<sortPom/>
```

have:
```xml
<sortPom>
  <expandEmptyElements>false</expandEmptyElements>
</sortPom>
```

reproducer:
- https://github.com/pmd/pmd/pull/5846


<img width="1055" alt="Image" src="https://github.com/user-attachments/assets/59ade91d-e326-44e6-978b-e05920fc56fc" />


Discussion:
  thanks.



Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 8c400b38fe..2f9e031795 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
 * Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
 * scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
 ### Fixed
+* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
 * Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
 * Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
 ### Changed
diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java
index 08a0308178..db37ae25fd 100644
--- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java
+++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2021-2024 DiffPlug
+ * Copyright 2021-2025 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ public class SortPomCfg implements Serializable {
 
 	public String lineSeparator = System.getProperty("line.separator");
 
-	public boolean expandEmptyElements = true;
+	public boolean expandEmptyElements;
 
 	public boolean spaceBeforeCloseEmptyElement = false;
 
diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
index aa150bf6cd..bf06a01e06 100644
--- a/plugin-maven/CHANGES.md
+++ b/plugin-maven/CHANGES.md
@@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
 * Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
 * Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
 ### Fixed
+* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
 * Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
 * Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
 ### Changed


Test patch:
diff --git a/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java b/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java
new file mode 100644
index 0000000000..b0a336f189
--- /dev/null
+++ b/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2025 DiffPlug
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.diffplug.spotless.pom;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class SortPomCfgTest {
+
+	@Test
+	void testDefaultValues() {
+		SortPomCfg cfg = new SortPomCfg();
+
+		// Test default values using AssertJ
+		assertThat(cfg.version).isEqualTo("4.0.0");
+		assertThat(cfg.encoding).isEqualTo("UTF-8");
+		assertThat(cfg.lineSeparator).isEqualTo(System.getProperty("line.separator"));
+		assertThat(cfg.expandEmptyElements).isFalse();
+		assertThat(cfg.spaceBeforeCloseEmptyElement).isFalse();
+		assertThat(cfg.keepBlankLines).isTrue();
+		assertThat(cfg.endWithNewline).isTrue();
+		assertThat(cfg.nrOfIndentSpace).isEqualTo(2);
+		assertThat(cfg.indentBlankLines).isFalse();
+		assertThat(cfg.indentSchemaLocation).isFalse();
+		assertThat(cfg.indentAttribute).isNull();
+		assertThat(cfg.predefinedSortOrder).isEqualTo("recommended_2008_06");
+		assertThat(cfg.quiet).isFalse();
+		assertThat(cfg.sortOrderFile).isNull();
+		assertThat(cfg.sortDependencies).isNull();
+		assertThat(cfg.sortDependencyManagement).isNull();
+		assertThat(cfg.sortDependencyExclusions).isNull();
+		assertThat(cfg.sortPlugins).isNull();
+		assertThat(cfg.sortProperties).isFalse();
+		assertThat(cfg.sortModules).isFalse();
+		assertThat(cfg.sortExecutions).isFalse();
+	}
+
+	@Test
+	void testFieldSetters() {
+		SortPomCfg cfg = new SortPomCfg();
+
+		// Set all fields
+		cfg.version = "4.1.0";
+		cfg.encoding = "ISO-8859-1";
+		cfg.lineSeparator = "\n";
+		cfg.expandEmptyElements = true;
+		cfg.spaceBeforeCloseEmptyElement = true;
+		cfg.keepBlankLines = false;
+		cfg.endWithNewline = false;
+		cfg.nrOfIndentSpace = 4;
+		cfg.indentBlankLines = true;
+		cfg.indentSchemaLocation = true;
+		cfg.indentAttribute = "attribute";
+		cfg.predefinedSortOrder = "custom";
+		cfg.quiet = true;
+		cfg.sortOrderFile = "sortOrder.xml";
+		cfg.sortDependencies = "groupId,artifactId";
+		cfg.sortDependencyManagement = "scope,groupId";
+		cfg.sortDependencyExclusions = "artifactId";
+		cfg.sortPlugins = "groupId";
+		cfg.sortProperties = true;
+		cfg.sortModules = true;
+		cfg.sortExecutions = true;
+
+		// Verify all set values with AssertJ
+		assertThat(cfg.version).isEqualTo("4.1.0");
+		assertThat(cfg.encoding).isEqualTo("ISO-8859-1");
+		assertThat(cfg.lineSeparator).isEqualTo("\n");
+		assertThat(cfg.expandEmptyElements).isTrue();
+		assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
+		assertThat(cfg.keepBlankLines).isFalse();
+		assertThat(cfg.endWithNewline).isFalse();
+		assertThat(cfg.nrOfIndentSpace).isEqualTo(4);
+		assertThat(cfg.indentBlankLines).isTrue();
+		assertThat(cfg.indentSchemaLocation).isTrue();
+		assertThat(cfg.indentAttribute).isEqualTo("attribute");
+		assertThat(cfg.predefinedSortOrder).isEqualTo("custom");
+		assertThat(cfg.quiet).isTrue();
+		assertThat(cfg.sortOrderFile).isEqualTo("sortOrder.xml");
+		assertThat(cfg.sortDependencies).isEqualTo("groupId,artifactId");
+		assertThat(cfg.sortDependencyManagement).isEqualTo("scope,groupId");
+		assertThat(cfg.sortDependencyExclusions).isEqualTo("artifactId");
+		assertThat(cfg.sortPlugins).isEqualTo("groupId");
+		assertThat(cfg.sortProperties).isTrue();
+		assertThat(cfg.sortModules).isTrue();
+		assertThat(cfg.sortExecutions).isTrue();
+	}
+
+	@Test
+	void testNullHandling() {
+		SortPomCfg cfg = new SortPomCfg();
+
+		// Set nullable fields to null
+		cfg.version = null;
+		cfg.encoding = null;
+		cfg.lineSeparator = null;
+		cfg.indentAttribute = null;
+		cfg.predefinedSortOrder = null;
+		cfg.sortOrderFile = null;
+		cfg.sortDependencies = null;
+		cfg.sortDependencyManagement = null;
+		cfg.sortDependencyExclusions = null;
+		cfg.sortPlugins = null;
+
+		// Verify null values with AssertJ
+		assertThat(cfg.version).isNull();
+		assertThat(cfg.encoding).isNull();
+		assertThat(cfg.lineSeparator).isNull();
+		assertThat(cfg.indentAttribute).isNull();
+		assertThat(cfg.predefinedSortOrder).isNull();
+		assertThat(cfg.sortOrderFile).isNull();
+		assertThat(cfg.sortDependencies).isNull();
+		assertThat(cfg.sortDependencyManagement).isNull();
+		assertThat(cfg.sortDependencyExclusions).isNull();
+		assertThat(cfg.sortPlugins).isNull();
+	}
+
+	@Test
+	void testBooleanFieldsEdgeCases() {
+		SortPomCfg cfg = new SortPomCfg();
+
+		// Toggle all boolean fields
+		cfg.expandEmptyElements = !cfg.expandEmptyElements;
+		cfg.spaceBeforeCloseEmptyElement = !cfg.spaceBeforeCloseEmptyElement;
+		cfg.keepBlankLines = !cfg.keepBlankLines;
+		cfg.endWithNewline = !cfg.endWithNewline;
+		cfg.indentBlankLines = !cfg.indentBlankLines;
+		cfg.indentSchemaLocation = !cfg.indentSchemaLocation;
+		cfg.quiet = !cfg.quiet;
+		cfg.sortProperties = !cfg.sortProperties;
+		cfg.sortModules = !cfg.sortModules;
+		cfg.sortExecutions = !cfg.sortExecutions;
+
+		// Verify all boolean fields are toggled
+		assertThat(cfg.expandEmptyElements).isTrue();
+		assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
+		assertThat(cfg.keepBlankLines).isFalse();
+		assertThat(cfg.endWithNewline).isFalse();
+		assertThat(cfg.indentBlankLines).isTrue();
+		assertThat(cfg.indentSchemaLocation).isTrue();
+		assertThat(cfg.quiet).isTrue();
+		assertThat(cfg.sortProperties).isTrue();
+		assertThat(cfg.sortModules).isTrue();
+		assertThat(cfg.sortExecutions).isTrue();
+	}
+
+	@Test
+	void testNumericFieldEdgeCases() {
+		SortPomCfg cfg = new SortPomCfg();
+
+		// Test minimum value
+		cfg.nrOfIndentSpace = 0;
+		assertThat(cfg.nrOfIndentSpace).isZero();
+
+		// Test negative value
+		cfg.nrOfIndentSpace = -1;
+		assertThat(cfg.nrOfIndentSpace).isNegative();
+
+		// Test large value
+		cfg.nrOfIndentSpace = Integer.MAX_VALUE;
+		assertThat(cfg.nrOfIndentSpace).isEqualTo(Integer.MAX_VALUE);
+	}
+}