Skip to content

Commit b7075bd

Browse files
ctruedenclaude
andcommitted
Fix extraneous whitespace in generated POM files
With Java 11 only (not 8, 17, or 21!), tests failed with errors like: java.lang.AssertionError: Unexpected: META-INF/maven/ org.scijava.scripting.java / Dummy /pom.xml Cause: the generated pom.xml has whitespace-polluted <groupId>, <artifactId>, and <version> values. Here's what was happening: 1. fakePOM() builds an XML document where each element's content is stored as a CDATA section via document.createCDATASection(content). 2. The transformer is configured with OutputKeys.INDENT = "yes". 3. In Java 8 (Xalan), the transformer writes CDATA content inline: <groupId><![CDATA[org.scijava.scripting.java]]></groupId>. 4. In Java 11, the internal XSLT transformer changed its indentation behavior for CDATA nodes — it treats a CDATA section as a child node distinct from inline text, and inserts a newline + indent before it and after it: <groupId> <![CDATA[org.scijava.scripting.java]]> </groupId> 5. When MiniMaven parses this POM back, getTextContent() on <groupId> returns "\n org.scijava.scripting.java\n ", which then gets embedded verbatim into the JAR entry path and into download URLs — causing the MalformedURLException and the wrong JAR entry names. The fix is in the append method: replace createCDATASection with createTextNode. XSLT transformers universally treat text-only elements (those with a single text-node child and no element children) as opaque and don't inject indentation whitespace inside them. CDATA sections and text nodes are semantically identical in XML, but Java 11's XSLT transformer treats a CDATA node as a distinct child and wraps it with indentation whitespace when INDENT=yes. Plain text nodes in text-only elements are left inline. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9ae808e commit b7075bd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ private static Element append(final Document document, final Element parent,
759759
{
760760
Element child = document.createElement(tag);
761761
if (content != null) child
762-
.appendChild(document.createCDATASection(content));
762+
.appendChild(document.createTextNode(content));
763763
parent.appendChild(child);
764764
return child;
765765
}

0 commit comments

Comments
 (0)