Skip to content

Commit 2f600b0

Browse files
committed
Fix #550
1 parent 183746c commit 2f600b0

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

release-notes/CREDITS-2.x

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,10 @@ Eric Law (ericcwlaw@github)
206206
* Reported #498: `XmlMapper` fails to parse XML array when the array only has one level
207207
(2.14.0)
208208

209+
David F. Elliott (dfelliott@github)
210+
211+
* Reported #550: Use of `ClassLoader`-taking `newFactory()` variant breaks applications
212+
using default JDK XML implementation
213+
(2.14.0)
214+
215+

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Project: jackson-dataformat-xml
1818
#545: `@JacksonXmlText` does not work when paired with `@JsonRawValue`
1919
(reported by James D)
2020
(fix contributed by Jonas K)
21+
#550: Use of `ClassLoader`-taking `newFactory()` variant breaks applications
22+
using default JDK XML implementation
23+
(reported by David-F E)
2124

2225
2.13.5 (not yet released)
2326

src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,16 @@ protected XmlFactory(ObjectCodec oc, int xpFeatures, int xgFeatures,
120120
_xmlGeneratorFeatures = xgFeatures;
121121
_cfgNameForTextElement = nameForTextElem;
122122
if (xmlIn == null) {
123-
// 05-Jul-2021, tatu: as per [dataformat-xml#483], specify ClassLoader
124-
xmlIn = XMLInputFactory.newFactory(XMLInputFactory.class.getName(),
125-
getClass().getClassLoader());
123+
xmlIn = StaxUtil.defaultInputFactory(getClass().getClassLoader());
126124
// as per [dataformat-xml#190], disable external entity expansion by default
127125
xmlIn.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
128126
// and ditto wrt [dataformat-xml#211], SUPPORT_DTD
129127
xmlIn.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
130128
}
131129
if (xmlOut == null) {
132-
// 05-Jul-2021, tatu: as per [dataformat-xml#483], specify ClassLoader
133-
xmlOut = XMLOutputFactory.newFactory(XMLOutputFactory.class.getName(),
134-
getClass().getClassLoader());
130+
xmlOut = StaxUtil.defaultOutputFactory(getClass().getClassLoader());
131+
// [dataformat-xml#326]: Better ensure namespaces get built properly:
132+
xmlOut.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
135133
}
136134
_initFactories(xmlIn, xmlOut);
137135
_xmlInputFactory = xmlIn;

src/main/java/com/fasterxml/jackson/dataformat/xml/XmlFactoryBuilder.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.core.TSFBuilder;
77
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
88
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
9+
import com.fasterxml.jackson.dataformat.xml.util.StaxUtil;
910

1011
/**
1112
* {@link com.fasterxml.jackson.core.TSFBuilder} implementation
@@ -109,10 +110,7 @@ public XMLInputFactory xmlInputFactory() {
109110
}
110111

111112
protected XMLInputFactory defaultInputFactory() {
112-
// 05-Jul-2021, tatu: as per [dataformat-xml#483], consider ClassLoader
113-
XMLInputFactory xmlIn = XMLInputFactory.newFactory(XMLInputFactory.class.getName(),
114-
staxClassLoader());
115-
113+
XMLInputFactory xmlIn = StaxUtil.defaultInputFactory(_classLoaderForStax);
116114
// as per [dataformat-xml#190], disable external entity expansion by default
117115
xmlIn.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
118116
// and ditto wrt [dataformat-xml#211], SUPPORT_DTD
@@ -128,9 +126,7 @@ public XMLOutputFactory xmlOutputFactory() {
128126
}
129127

130128
protected XMLOutputFactory defaultOutputFactory() {
131-
// 05-Jul-2021, tatu: as per [dataformat-xml#483], consider ClassLoader
132-
XMLOutputFactory xmlOut = XMLOutputFactory.newFactory(XMLOutputFactory.class.getName(),
133-
staxClassLoader());
129+
XMLOutputFactory xmlOut = StaxUtil.defaultOutputFactory(_classLoaderForStax);
134130
// [dataformat-xml#326]: Better ensure namespaces get built properly:
135131
xmlOut.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
136132
return xmlOut;

src/main/java/com/fasterxml/jackson/dataformat/xml/util/StaxUtil.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,32 @@ public static org.codehaus.stax2.typed.Base64Variant toStax2Base64Variant(Base64
135135
return Base64Mapper.instance.map(j64b);
136136
}
137137

138+
/**
139+
* @since 2.14
140+
*/
141+
public static XMLInputFactory defaultInputFactory(ClassLoader cl) {
142+
// 05-Jul-2021, tatu: as per [dataformat-xml#483], specify ClassLoader
143+
try {
144+
return XMLInputFactory.newFactory(XMLInputFactory.class.getName(), cl);
145+
} catch (FactoryConfigurationError e) {
146+
// 24-Oct-2022, tatu: as per [dataformat-xml#550] need extra care
147+
return XMLInputFactory.newFactory();
148+
}
149+
}
150+
151+
/**
152+
* @since 2.14
153+
*/
154+
public static XMLOutputFactory defaultOutputFactory(ClassLoader cl) {
155+
// 05-Jul-2021, tatu: as per [dataformat-xml#483], specify ClassLoader
156+
try {
157+
return XMLOutputFactory.newFactory(XMLOutputFactory.class.getName(), cl);
158+
} catch (FactoryConfigurationError e) {
159+
// 24-Oct-2022, tatu: as per [dataformat-xml#550] need extra care
160+
return XMLOutputFactory.newFactory();
161+
}
162+
}
163+
138164
private static class Base64Mapper {
139165
public final static Base64Mapper instance = new Base64Mapper();
140166

0 commit comments

Comments
 (0)