[Git][java-team/jackson-dataformat-xml][upstream] New upstream version 2.23.0
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Mon Nov 9 17:06:30 GMT 2026
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / jackson-dataformat-xml
Commits:
fd8075ef by Emmanuel Bourg at 2026-11-09T17:07:38+01:00
New upstream version 2.23.0
- - - - -
11 changed files:
- .github/workflows/main.yml
- pom.xml
- release-notes/CREDITS-2.x
- release-notes/VERSION-2.x
- src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java
- src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/lists/EmptyListDeserTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/lists/NestedUnwrappedLists86Test.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/misc/XmlTextTest.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/stream/BinaryUnknownLengthWriteTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/stream/XmlParserNextXxxTest.java
Changes:
=====================================
.github/workflows/main.yml
=====================================
@@ -56,7 +56,7 @@ jobs:
run: ./mvnw -B -q -ff -ntp test
- name: Publish code coverage
if: ${{ matrix.release_build && github.event_name != 'pull_request' }}
- uses: codecov/codecov-action at 5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
+ uses: codecov/codecov-action at 303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./target/site/jacoco/jacoco.xml
=====================================
pom.xml
=====================================
@@ -9,11 +9,11 @@
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
- <version>2.22.4</version>
+ <version>2.23.0</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
- <version>2.22.4</version>
+ <version>2.23.0</version>
<name>Jackson-dataformat-XML</name>
<packaging>jar</packaging>
<description>Data format extension for Jackson to offer
@@ -24,7 +24,7 @@ alternative support for serializing POJOs as XML and deserializing XML as POJOs.
<connection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</connection>
<developerConnection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</developerConnection>
<url>http://github.com/FasterXML/jackson-dataformat-xml</url>
- <tag>jackson-dataformat-xml-2.22.4</tag>
+ <tag>jackson-dataformat-xml-2.23.0</tag>
</scm>
<properties>
<packageVersion.dir>com/fasterxml/jackson/dataformat/xml</packageVersion.dir>
@@ -34,7 +34,7 @@ alternative support for serializing POJOs as XML and deserializing XML as POJOs.
<!-- And presumably import too? -->
<!-- for Reproducible Builds -->
- <project.build.outputTimestamp>2026-10-17T23:30:33Z</project.build.outputTimestamp>
+ <project.build.outputTimestamp>2026-11-08T00:58:55Z</project.build.outputTimestamp>
</properties>
<dependencies>
=====================================
release-notes/CREDITS-2.x
=====================================
@@ -287,3 +287,9 @@ 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)
+* Fixed #894: `ToXmlGenerator.writeBinary(Base64Variant, InputStream, int)` fails with
+ `NegativeArraySizeException`/`IndexOutOfBoundsException` for unknown (negative) length
+ (2.23.0)
=====================================
release-notes/VERSION-2.x
=====================================
@@ -4,6 +4,15 @@ Project: jackson-dataformat-xml
=== Releases ===
------------------------------------------------------------------------
+2.23.0 (07-Nov-2026)
+
+#899: Return `null` from `nextTextValue()` at end-of-input (instead of
+ throwing `IllegalStateException`)
+ (fix by @Sahana2524)
+#894: `ToXmlGenerator.writeBinary(Base64Variant, InputStream, int)` fails with
+ `NegativeArraySizeException`/`IndexOutOfBoundsException` for unknown (negative) length
+ (fix by @Sahana2524)
+
2.22.4 (17-Oct-2026)
2.22.3 (21-Sep-2026)
2.22.2 (16-Aug-2026)
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java
=====================================
@@ -1052,6 +1052,7 @@ XmlTokenStream.XML_END_ELEMENT, XmlTokenStream.XML_START_ELEMENT, token));
break;
case XmlTokenStream.XML_END:
_updateTokenToNull();
+ break;
default:
return _internalErrorUnknownToken(token);
}
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
=====================================
@@ -18,6 +18,7 @@ import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.GeneratorBase;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.json.JsonWriteContext;
+import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.dataformat.xml.XmlPrettyPrinter;
import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter;
@@ -1011,6 +1012,18 @@ public class ToXmlGenerator
}
}
+ /**
+ * Implementation follows the {@link JsonGenerator} contract in which negative
+ * {@code dataLength} means "length unknown": stream is then read until end-of-stream.
+ *<p>
+ * NOTE: values written as XML elements are streamed in fixed-size chunks, but values
+ * written as attributes (or with a pretty-printer) have to be buffered in memory in
+ * full, since Stax2 API only offers "full buffer" methods for those cases.
+ *
+ * @param dataLength Number of bytes to write, if known; negative value if unknown
+ *
+ * @return Number of bytes read from {@code data} and written as binary payload
+ */
@Override
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) throws IOException
{
@@ -1023,24 +1036,30 @@ public class ToXmlGenerator
handleMissingName();
}
final org.codehaus.stax2.typed.Base64Variant stax2base64v = StaxUtil.toStax2Base64Variant(b64variant);
+ // 22-Aug-2026, sahana: negative `dataLength` means "unknown, read to the end";
+ // stream where we can, buffer only where Stax2 needs a full buffer
+ int written = dataLength;
try {
if (_nextIsAttribute) {
// Stax2 API only has 'full buffer' write method:
- byte[] fullBuffer = toFullBuffer(data, dataLength);
+ byte[] fullBuffer = (dataLength < 0) ? toFullBuffer(data) : toFullBuffer(data, dataLength);
+ written = fullBuffer.length;
_xmlWriter.writeBinaryAttribute(stax2base64v,
"", _nextName.getNamespaceURI(), _nextName.getLocalPart(), fullBuffer);
} else if (checkNextIsUnwrapped()) {
// should we consider pretty-printing or not?
- writeStreamAsBinary(stax2base64v, data, dataLength);
+ written = writeStreamAsBinary(stax2base64v, data, dataLength);
} else {
if (_xmlPrettyPrinter != null) {
+ byte[] fullBuffer = (dataLength < 0) ? toFullBuffer(data) : toFullBuffer(data, dataLength);
+ written = fullBuffer.length;
_xmlPrettyPrinter.writeLeafElement(_xmlWriter,
_nextName.getNamespaceURI(), _nextName.getLocalPart(),
- stax2base64v, toFullBuffer(data, dataLength), 0, dataLength);
+ stax2base64v, fullBuffer, 0, written);
} else {
_xmlWriter.writeStartElement(_nextName.getNamespaceURI(), _nextName.getLocalPart());
- writeStreamAsBinary(stax2base64v, data, dataLength);
+ written = writeStreamAsBinary(stax2base64v, data, dataLength);
_xmlWriter.writeEndElement();
}
}
@@ -1048,32 +1067,77 @@ public class ToXmlGenerator
StaxUtil.throwAsGenerationException(e, this);
}
- return dataLength;
+ return written;
}
- private void writeStreamAsBinary(org.codehaus.stax2.typed.Base64Variant stax2base64v,
+ /**
+ * Helper method for encoding contents of given stream: at most {@code len}
+ * bytes if non-negative, or until end-of-stream if negative. Content is read
+ * and encoded in fixed-size chunks so memory usage does not depend on its length;
+ * preferred over {@link #toFullBuffer} where Stax2 API allows it.
+ *
+ * @return Number of bytes read and encoded
+ */
+ private int writeStreamAsBinary(org.codehaus.stax2.typed.Base64Variant stax2base64v,
InputStream data, int len) throws IOException, XMLStreamException
{
- // base64 encodes up to 3 bytes into a 4 bytes string
- byte[] tmp = new byte[3];
- int offset = 0;
- int read;
- while((read = data.read(tmp, offset, Math.min(3 - offset, len))) != -1) {
- offset += read;
- len -= read;
- if(offset == 3) {
- offset = 0;
- _xmlWriter.writeBinary(stax2base64v, tmp, 0, 3);
- }
- if (len == 0) {
- break;
+ final byte[] buf = _ioContext.allocBase64Buffer();
+ final int unit = _base64ChunkUnit(stax2base64v, buf.length);
+ int total = 0;
+ try {
+ int end = 0; // number of buffered bytes not yet written
+ while (true) {
+ int max = buf.length - end;
+ if (len >= 0 && len < max) {
+ max = len;
+ }
+ int count = (max == 0) ? -1 : data.read(buf, end, max);
+ if (count < 0) { // end-of-stream, or requested length reached
+ if (end > 0) {
+ _xmlWriter.writeBinary(stax2base64v, buf, 0, end);
+ }
+ break;
+ }
+ end += count;
+ total += count;
+ if (len > 0) {
+ len -= count;
+ }
+ // Write out complete chunks, keep the remainder for the next round
+ int full = end - (end % unit);
+ if (full > 0) {
+ _xmlWriter.writeBinary(stax2base64v, buf, 0, full);
+ end -= full;
+ System.arraycopy(buf, full, buf, 0, end);
+ }
}
+ } finally {
+ _ioContext.releaseBase64Buffer(buf);
}
+ return total;
+ }
- // we still have < 3 bytes in the buffer
- if(offset > 0) {
- _xmlWriter.writeBinary(stax2base64v, tmp, 0, offset);
+ /**
+ * Helper method for figuring out granularity of chunks to pass to Stax2
+ * {@code writeBinary()}: Base64 encodes 3 bytes into 4 characters so chunks must
+ * be multiples of 3 -- and if variant uses linefeeds, must also align with line
+ * boundaries, since Stax2 encoder restarts its line-length counter on every call.
+ *
+ * @return Chunk length granularity to use; always a multiple of 3
+ */
+ private static int _base64ChunkUnit(org.codehaus.stax2.typed.Base64Variant b64v,
+ int bufferLength)
+ {
+ final int maxLineLength = b64v.getMaxLineLength();
+ if (maxLineLength > 0 && maxLineLength < Integer.MAX_VALUE) {
+ // 4 encoded characters per each 3 bytes of input
+ final int lineBytes = (maxLineLength >> 2) * 3;
+ // But cannot align if a single line won't fit in the read buffer
+ if (lineBytes >= 3 && lineBytes <= bufferLength) {
+ return lineBytes;
+ }
}
+ return 3;
}
private byte[] toFullBuffer(byte[] data, int offset, int len)
@@ -1089,6 +1153,11 @@ public class ToXmlGenerator
return result;
}
+ /**
+ * Helper method for reading exactly {@code len} bytes into a newly allocated
+ * buffer, for cases where Stax2 API requires the full value; fails if stream
+ * does not contain that many bytes.
+ */
private byte[] toFullBuffer(InputStream data, final int len) throws IOException
{
byte[] result = new byte[len];
@@ -1104,6 +1173,35 @@ public class ToXmlGenerator
return result;
}
+ /**
+ * Variant of {@link #toFullBuffer(InputStream, int)} for unknown length: reads
+ * until end-of-stream.
+ *<p>
+ * NOTE: since length is not known in advance no allocation limit can be applied,
+ * and an arbitrarily large stream is accumulated until exhausted (or memory runs
+ * out); prefer {@link #writeStreamAsBinary} wherever streaming is possible.
+ */
+ private byte[] toFullBuffer(InputStream data) throws IOException
+ {
+ final byte[] tmp = _ioContext.allocBase64Buffer();
+ final ByteArrayBuilder bb = new ByteArrayBuilder(_ioContext.bufferRecycler());
+ byte[] result = null;
+ try {
+ int count;
+ while ((count = data.read(tmp)) >= 0) {
+ bb.write(tmp, 0, count);
+ }
+ result = bb.getClearAndRelease();
+ } finally {
+ _ioContext.releaseBase64Buffer(tmp);
+ // If read failed, builder still holds on to a recycled buffer: return it
+ if (result == null) {
+ bb.release();
+ }
+ }
+ return result;
+ }
+
/*
/**********************************************************
/* Output method implementations, primitive
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/lists/EmptyListDeserTest.java
=====================================
@@ -66,7 +66,8 @@ public class EmptyListDeserTest extends XmlTestUtil
private final XmlMapper MAPPER = newMapper();
// [dataformat-xml#124]
- public void test124() throws Exception {
+ @Test
+ public void test124() throws Exception {
TestList124 originalObject = new TestList124();
originalObject.list = new ArrayList<Object>();
String xml = MAPPER.writeValueAsString(originalObject);
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/lists/NestedUnwrappedLists86Test.java
=====================================
@@ -85,7 +85,7 @@ public class NestedUnwrappedLists86Test extends XmlTestUtil
new Issue86("0.3.1", null)))));
final XmlMapper mapper = new XmlMapper();
- mapper.setSerializationInclusion(Include.NON_NULL);
+ mapper.setDefaultPropertyInclusion(Include.NON_NULL);
final String xml = mapper.writeValueAsString(before);
assertEquals(sourceCompact, xml);
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/misc/XmlTextTest.java
=====================================
@@ -69,7 +69,7 @@ public class XmlTextTest extends XmlTestUtil
public void testXmlTextWithSuppressedValue() throws Exception
{
final XmlMapper mapper = new XmlMapper();
- mapper.setSerializationInclusion(Include.NON_EMPTY);
+ mapper.setDefaultPropertyInclusion(Include.NON_EMPTY);
String xml = mapper.writeValueAsString(new Data("","second"));
String expectedXml = "<Data><second>second</second></Data>";
assertEquals(expectedXml, xml);
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/stream/BinaryUnknownLengthWriteTest.java
=====================================
@@ -0,0 +1,269 @@
+package com.fasterxml.jackson.dataformat.xml.stream;
+
+import java.io.ByteArrayInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.core.Base64Variant;
+import com.fasterxml.jackson.core.Base64Variants;
+
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestUtil;
+import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+
+// [dataformat-xml#894]: `JsonGenerator.writeBinary(InputStream, dataLength)` documents a
+// negative `dataLength` as "length unknown, read to end" (the JSON backend honors it);
+// verify the XML backend streams to end instead of failing with a raw runtime exception.
+public class BinaryUnknownLengthWriteTest extends XmlTestUtil
+{
+ // Stream that hands out a single byte per read() call
+ static class ShortReadInputStream extends FilterInputStream
+ {
+ ShortReadInputStream(InputStream in) { super(in); }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ return super.read(b, off, Math.min(len, 1));
+ }
+ }
+
+ // Stream that fails partway through, to verify buffers are recycled properly
+ static class FailingInputStream extends InputStream
+ {
+ private int _left;
+
+ FailingInputStream(int okBytes) { _left = okBytes; }
+
+ @Override
+ public int read() throws IOException {
+ byte[] b = new byte[1];
+ int count = read(b, 0, 1);
+ return (count < 0) ? -1 : (b[0] & 0xFF);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (_left <= 0) {
+ throw new IOException("Test-induced read failure");
+ }
+ int count = Math.min(len, _left);
+ _left -= count;
+ return count;
+ }
+ }
+
+ private final XmlMapper MAPPER = newMapper();
+
+ private final byte[] DATA = utf8Bytes("hello, binary world");
+ // base64 of DATA
+ private final String ENCODED = "aGVsbG8sIGJpbmFyeSB3b3JsZA==";
+
+ @Test
+ public void testElementUnknownLength() throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ assertEquals(DATA.length,
+ gen.writeBinary(Base64Variants.MIME, new ByteArrayInputStream(DATA), -1));
+ gen.writeEndObject();
+ }
+ assertEquals("<root><bin>" + ENCODED + "</bin></root>", removeSjsxpNamespace(out.toString()));
+ }
+
+ @Test
+ public void testAttributeUnknownLength() throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.setNextIsAttribute(true);
+ gen.writeFieldName("bin");
+ assertEquals(DATA.length,
+ gen.writeBinary(Base64Variants.MIME, new ByteArrayInputStream(DATA), -1));
+ gen.writeEndObject();
+ }
+ assertEquals("<root bin=\"" + ENCODED + "\"/>", removeSjsxpNamespace(out.toString()));
+ }
+
+ @Test
+ public void testUnwrappedUnknownLength() throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ gen.setNextIsUnwrapped(true);
+ assertEquals(DATA.length,
+ gen.writeBinary(Base64Variants.MIME, new ByteArrayInputStream(DATA), -1));
+ gen.writeEndObject();
+ }
+ assertEquals("<root>" + ENCODED + "</root>", removeSjsxpNamespace(out.toString()));
+ }
+
+ @Test
+ public void testPrettyPrintedUnknownLength() throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.writerWithDefaultPrettyPrinter()
+ .createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ assertEquals(DATA.length,
+ gen.writeBinary(Base64Variants.MIME, new ByteArrayInputStream(DATA), -1));
+ gen.writeEndObject();
+ }
+ assertEquals("<root>\n <bin>" + ENCODED + "</bin>\n</root>\n",
+ removeSjsxpNamespace(out.toString()));
+ }
+
+ // Empty stream should render the same whether length is given as 0 or unknown
+ @Test
+ public void testEmptyStream() throws Exception
+ {
+ final byte[] empty = new byte[0];
+ assertEquals("<root><bin/></root>", _writeElement(Base64Variants.MIME, empty, 0));
+ assertEquals("<root><bin/></root>", _writeElement(Base64Variants.MIME, empty, -1));
+ assertEquals("<root bin=\"\"/>", _writeAttribute(Base64Variants.MIME, empty, 0));
+ assertEquals("<root bin=\"\"/>", _writeAttribute(Base64Variants.MIME, empty, -1));
+ }
+
+ // Payload bigger than the recycled read buffer, and not a multiple of 3, so that
+ // partial triplets have to be carried over between reads
+ @Test
+ public void testLargePayloadUnknownLength() throws Exception
+ {
+ _testLargePayload(Base64Variants.MIME_NO_LINEFEEDS, Integer.MAX_VALUE);
+ // and same for a variant that does use linefeeds: chunk boundaries must
+ // align with line boundaries, or lines would end up longer than allowed
+ _testLargePayload(Base64Variants.MIME, 76);
+ _testLargePayload(Base64Variants.PEM, 64);
+ }
+
+ private void _testLargePayload(Base64Variant b64v, int maxLineLength) throws Exception
+ {
+ final byte[] big = new byte[7001];
+ for (int i = 0; i < big.length; i++) {
+ big[i] = (byte) i;
+ }
+ // Streaming output must match what the `byte[]` overload produces
+ final String expected = _writeElement(b64v, big);
+ final String actual = _writeElement(b64v, big, -1);
+ assertEquals(expected, actual);
+ assertEquals(expected, _writeElement(b64v, big, big.length));
+ assertEquals(_writeAttribute(b64v, big, big.length), _writeAttribute(b64v, big, -1));
+
+ // and no line may exceed the maximum length variant specifies
+ String encoded = actual.substring("<root><bin>".length(), actual.length() - "</bin></root>".length());
+ for (String line : encoded.split("\n", -1)) {
+ if (line.length() > maxLineLength) {
+ fail("Line length "+line.length()+" exceeds max "+maxLineLength+" for "+b64v.getName());
+ }
+ }
+
+ // and finally, make sure it decodes back
+ assertArrayEquals(big, b64v.decode(encoded));
+ }
+
+ @Test
+ public void testShortReadsUnknownLength() throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ assertEquals(DATA.length, gen.writeBinary(Base64Variants.MIME,
+ new ShortReadInputStream(new ByteArrayInputStream(DATA)), -1));
+ gen.writeEndObject();
+ }
+ assertEquals("<root><bin>" + ENCODED + "</bin></root>", removeSjsxpNamespace(out.toString()));
+ }
+
+ // Failure partway through an unknown-length read must not leave recycled buffers
+ // in a bad state: following writes must still produce correct output
+ @Test
+ public void testFailingStreamReleasesBuffers() throws Exception
+ {
+ for (int i = 0; i < 3; ++i) {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.setNextIsAttribute(true);
+ gen.writeFieldName("bin");
+ assertThrows(IOException.class, () -> gen.writeBinary(Base64Variants.MIME,
+ new FailingInputStream(5000), -1));
+ } catch (IOException e) {
+ // close() may fail due to incomplete output; ignore
+ }
+ // and then verify that buffer recycling still works as expected
+ assertEquals("<root><bin>" + ENCODED + "</bin></root>", _writeElement(
+ Base64Variants.MIME, DATA, -1));
+ }
+ }
+
+ /*
+ /**********************************************************************
+ /* Helper methods
+ /**********************************************************************
+ */
+
+ private String _writeElement(Base64Variant b64v, byte[] data) throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ gen.writeBinary(b64v, data, 0, data.length);
+ gen.writeEndObject();
+ }
+ return removeSjsxpNamespace(out.toString());
+ }
+
+ private String _writeElement(Base64Variant b64v, byte[] data, int dataLength) throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.writeFieldName("bin");
+ assertEquals(data.length,
+ gen.writeBinary(b64v, new ByteArrayInputStream(data), dataLength));
+ gen.writeEndObject();
+ }
+ return removeSjsxpNamespace(out.toString());
+ }
+
+ private String _writeAttribute(Base64Variant b64v, byte[] data, int dataLength) throws Exception
+ {
+ StringWriter out = new StringWriter();
+ try (ToXmlGenerator gen = (ToXmlGenerator) MAPPER.createGenerator(out)) {
+ gen.setNextName(new QName("root"));
+ gen.writeStartObject();
+ gen.setNextIsAttribute(true);
+ gen.writeFieldName("bin");
+ assertEquals(data.length,
+ gen.writeBinary(b64v, new ByteArrayInputStream(data), dataLength));
+ gen.writeEndObject();
+ }
+ return removeSjsxpNamespace(out.toString());
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/stream/XmlParserNextXxxTest.java
=====================================
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlTestUtil;
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
{
@@ -57,4 +58,26 @@ public class XmlParserNextXxxTest extends XmlTestUtil
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();
+ }
}
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/-/commit/fd8075ef1a7af0e1552ca97c666c7787a71ab6b8
--
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/-/commit/fd8075ef1a7af0e1552ca97c666c7787a71ab6b8
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261109/e15a53ce/attachment.htm>
More information about the pkg-java-commits
mailing list