From 9942501d7d273b724dc077db0611bd754f1de3cb Mon Sep 17 00:00:00 2001 From: Rainer Prosi Date: Tue, 25 Jun 2024 17:14:16 +0200 Subject: [PATCH] improved getCommentText for null value --- src/main/java/org/cip4/jdflib/core/JDFElement.java | 6 ++++-- src/test/java/org/cip4/jdflib/node/JDFNodeTest.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cip4/jdflib/core/JDFElement.java b/src/main/java/org/cip4/jdflib/core/JDFElement.java index 9987ac477..e61229870 100644 --- a/src/main/java/org/cip4/jdflib/core/JDFElement.java +++ b/src/main/java/org/cip4/jdflib/core/JDFElement.java @@ -4070,7 +4070,7 @@ public VString getInvalidElements_JDFElement(final EnumValidationLevel level, fi vBad.appendUnique(new VString(getDeprecatedElements(nMax))); if (nMax <= 0 || vBad.size() < nMax) { - VString prereleaseElements = getPrereleaseElements(nMax); + final VString prereleaseElements = getPrereleaseElements(nMax); vBad.appendUnique(new VString(prereleaseElements)); } } @@ -6338,7 +6338,9 @@ public JDFComment getComment(final String _name, final int index) */ public String getCommentText(final String _name, final int index) { - final JDFComment c = getComment(_name, index); + JDFComment c = getComment(_name, index); + if (c == null && StringUtil.isEmpty(_name)) + c = getComment(index); return c == null ? null : c.getText(); } diff --git a/src/test/java/org/cip4/jdflib/node/JDFNodeTest.java b/src/test/java/org/cip4/jdflib/node/JDFNodeTest.java index 0d2230094..e3502bc7f 100644 --- a/src/test/java/org/cip4/jdflib/node/JDFNodeTest.java +++ b/src/test/java/org/cip4/jdflib/node/JDFNodeTest.java @@ -202,10 +202,12 @@ void testComment() final JDFNode n = JDFNode.createRoot(); n.setCommentText("foo"); assertEquals("foo", n.getComment(0).getText()); + assertEquals("foo", n.getCommentText(null, 0)); n.setCommentText("next", "bar"); assertEquals("next", n.getCommentText("bar", 0)); assertEquals(null, n.getCommentText("foo", 0)); assertEquals(null, n.getCommentText("bar", 1)); + assertEquals("next", n.getCommentText(null, 1)); } /**