diff --git a/sorter/src/main/java/sortpom/content/NewlineText.java b/sorter/src/main/java/sortpom/content/NewlineText.java index 4d0c5e6f..fc0e1085 100644 --- a/sorter/src/main/java/sortpom/content/NewlineText.java +++ b/sorter/src/main/java/sortpom/content/NewlineText.java @@ -7,11 +7,8 @@ * in XmlProcessor.PatchedXMLWriter */ public class NewlineText extends AbstractText { - public static final NewlineText INSTANCE = new NewlineText(); private static final long serialVersionUID = -7552189498553321263L; - private NewlineText() {} - /** * This returns a String representation of the NewlineText, suitable for * debugging. diff --git a/sorter/src/main/java/sortpom/wrapper/TextWrapperCreator.java b/sorter/src/main/java/sortpom/wrapper/TextWrapperCreator.java index b487e736..8a172ea7 100644 --- a/sorter/src/main/java/sortpom/wrapper/TextWrapperCreator.java +++ b/sorter/src/main/java/sortpom/wrapper/TextWrapperCreator.java @@ -36,7 +36,7 @@ Wrapper createWrapper(Text text) { return new UnsortedWrapper<>(text); } - private boolean isElementSpacePreserved(Element element) { + boolean isElementSpacePreserved(Element element) { if (element == null) { return false; } diff --git a/sorter/src/main/java/sortpom/wrapper/content/UnsortedWrapper.java b/sorter/src/main/java/sortpom/wrapper/content/UnsortedWrapper.java index e2410826..777d7289 100644 --- a/sorter/src/main/java/sortpom/wrapper/content/UnsortedWrapper.java +++ b/sorter/src/main/java/sortpom/wrapper/content/UnsortedWrapper.java @@ -7,7 +7,7 @@ /** A wrapper that lets is element be unsorted */ public class UnsortedWrapper implements Wrapper { public static final UnsortedWrapper NEWLINE_TEXT_WRAPPER_INSTANCE = - new UnsortedWrapper<>(NewlineText.INSTANCE); + new UnsortedWrapper<>(new NewlineText()); /** The wrapped dom content. */ private final T content; diff --git a/sorter/src/test/java/sortpom/wrapper/TextWrapperCreatorTest.java b/sorter/src/test/java/sortpom/wrapper/TextWrapperCreatorTest.java index 726ab3d6..a2f91c34 100644 --- a/sorter/src/test/java/sortpom/wrapper/TextWrapperCreatorTest.java +++ b/sorter/src/test/java/sortpom/wrapper/TextWrapperCreatorTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.dom4j.dom.DOMText; import org.dom4j.tree.DefaultText; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,4 +41,10 @@ void testIsEmptyLine() { assertTrue(textWrapperCreator.isBlankLineOrLines(new DefaultText("\r\n\r\n"))); assertFalse(textWrapperCreator.isBlankLineOrLines(new DefaultText(" "))); } + + @Test + void textNodeWithNullParentShouldNotCrash() { + var text = new DOMText("Hi!"); + assertFalse(textWrapperCreator.isElementSpacePreserved(text.getParent())); + } }