Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public Xpp3Dom(String name) {
childMap = new HashMap<>();
}

boolean isValueSet() {
return value != null;
}

/**
* Create instance.
*
Expand Down Expand Up @@ -140,7 +144,7 @@ public String getName() {
*/
@NonNull
public String getValue() {
return value;
return value != null ? value : "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static void write(XMLWriter xmlWriter, Xpp3Dom dom, boolean escape) throw
write(xmlWriter, aChildren, escape);
}

String value = dom.getValue();
if (value != null) {
if (dom.isValueSet()) {
String value = dom.getValue();
if (escape) {
xmlWriter.writeText(value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.apache.maven.shared.utils.xml.Xpp3Dom.mergeXpp3Dom;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
Expand All @@ -42,6 +42,13 @@ private Xpp3Dom createElement(String element, String value) {
return t1s1;
}

@Test
public void defaultValueIsNotNull() {
// getValue() is annotated @NonNull but the one-arg constructor
// did not initialize value, violating the contract.
assertNotNull(new Xpp3Dom("test").getValue());
}

@Test
public void mergePrecedenceSelfClosed() throws XmlPullParserException {
Xpp3Dom parentConfig = build("<configuration><items><item/></items></configuration>");
Expand Down Expand Up @@ -82,7 +89,7 @@ public void selfOverrideOnRootNode() {
Xpp3Dom result = mergeXpp3Dom(t1, t2);

assertEquals(2, result.getAttributeNames().length);
assertNull(result.getValue());
assertEquals("", result.getValue());
}

@Test
Expand Down
Loading