From 8975133b3534d747dc45a0a6e2e338cdf0470f1a Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 3 Jul 2021 18:43:40 -0700 Subject: [PATCH] Backport #482 in 2.11 just in case (unlikely to have full release tho) --- release-notes/VERSION-2.x | 3 ++- .../jackson/dataformat/xml/XmlFactory.java | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 67a819191..af7116ab0 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -4,10 +4,11 @@ Project: jackson-dataformat-xml === Releases === ------------------------------------------------------------------------ -2.11.5 (not yet released) +Fixes in 2.11 branch, not released (may or may not be released) #456: Fix JsonAlias with unwrapped lists (contributed by Westin M) +#482: Use of non-Stax2-compatible Stax2 implementation fails when reading from byte[] - Upgrade Woodstox dependency to 6.2.4 (<- 6.2.3) 2.11.4 (12-Dec-2020) diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java index 3ab6f713b..d1b99e98c 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java @@ -4,6 +4,7 @@ import javax.xml.stream.*; +import org.codehaus.stax2.XMLInputFactory2; import org.codehaus.stax2.io.Stax2ByteArraySource; import org.codehaus.stax2.io.Stax2CharArraySource; @@ -600,7 +601,13 @@ protected FromXmlParser _createParser(char[] data, int offset, int len, IOContex // is always same as if 'false' was passed XMLStreamReader sr; try { - sr = _xmlInputFactory.createXMLStreamReader(new Stax2CharArraySource(data, offset, len)); + // 03-Jul-2021, tatu: [dataformat-xml#482] non-Stax2 impls unlikely to + // support so avoid: + if (_xmlInputFactory instanceof XMLInputFactory2) { + sr = _xmlInputFactory.createXMLStreamReader(new Stax2CharArraySource(data, offset, len)); + } else { + sr = _xmlInputFactory.createXMLStreamReader(new CharArrayReader(data, offset, len)); + } } catch (XMLStreamException e) { return StaxUtil.throwAsParseException(e, null); } @@ -618,7 +625,13 @@ protected FromXmlParser _createParser(byte[] data, int offset, int len, IOContex { XMLStreamReader sr; try { - sr = _xmlInputFactory.createXMLStreamReader(new Stax2ByteArraySource(data, offset, len)); + // 03-Jul-2021, tatu: [dataformat-xml#482] non-Stax2 impls unlikely to + // support so avoid: + if (_xmlInputFactory instanceof XMLInputFactory2) { + sr = _xmlInputFactory.createXMLStreamReader(new Stax2ByteArraySource(data, offset, len)); + } else { + sr = _xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(data, offset, len)); + } } catch (XMLStreamException e) { return StaxUtil.throwAsParseException(e, null); }