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
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,6 @@ Sahana (@Sahana2524)
* Contributed #891: Enforce `StreamReadConstraints.maxNestingDepth` in
`FromXmlParser`
(2.18.10)
* Fixed #899: Return `null` from `nextTextValue()` at end-of-input (instead of
throwing `IllegalStateException`)
(2.23.0)
4 changes: 3 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Project: jackson-dataformat-xml

2.23.0 (not yet released)

No changes since 2.22
#899: Return `null` from `nextTextValue()` at end-of-input (instead of
throwing `IllegalStateException`)
(fix by @Sahana2524)

2.22.2 (16-Aug-2026)
2.22.1 (07-Jul-2026)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ public String nextTextValue() throws IOException
break;
case XmlTokenStream.XML_END:
_updateTokenToNull();
break;
default:
return _internalErrorUnknownToken(token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class XmlParserNextXxxTest extends XmlTestUtil
{
Expand Down Expand Up @@ -57,4 +58,26 @@ public void testXmlAttributesWithNextTextValue() throws Exception
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // </data>
xp.close();
}

// [dataformat-xml#899]: nextTextValue() must honor the JsonParser contract
// at end of input: return null, same as nextToken() does, instead of leaking
// an unchecked IllegalStateException from the internal XML_END branch.
@Test
public void testNextTextValueAtEndOfInput() throws Exception
{
final String XML = "<data max=\"7\" offset=\"9\"/>";

FromXmlParser xp = (FromXmlParser) _xmlFactory.createParser(new StringReader(XML));

assertToken(JsonToken.START_OBJECT, xp.nextToken()); // <data>
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // max
assertEquals("7", xp.nextTextValue());
assertToken(JsonToken.FIELD_NAME, xp.nextToken()); // offset
assertEquals("9", xp.nextTextValue());
assertToken(JsonToken.END_OBJECT, xp.nextToken()); // </data>

// One more call past the end: should quietly report end-of-input
assertNull(xp.nextTextValue());
xp.close();
}
}