Skip to content

Commit 3074bad

Browse files
soupslurprrzo1
authored andcommitted
OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android
1 parent aeaa7d2 commit 3074bad

File tree

1 file changed

+12
-1
lines changed
  • opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util

1 file changed

+12
-1
lines changed

opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/XmlUtil.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
import javax.xml.parsers.SAXParser;
2525
import javax.xml.parsers.SAXParserFactory;
2626

27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729
import org.xml.sax.SAXException;
2830

2931
public class XmlUtil {
3032

33+
private static final Logger logger = LoggerFactory.getLogger(XmlUtil.class);
34+
3135
/**
3236
* Create a new {@link DocumentBuilder} which processes XML securely.
3337
*
@@ -38,7 +42,14 @@ public class XmlUtil {
3842
public static DocumentBuilder createDocumentBuilder() {
3943
try {
4044
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
41-
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
45+
try {
46+
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
47+
} catch (ParserConfigurationException e) {
48+
/// {@link XMLConstants.FEATURE_SECURE_PROCESSING} is not supported on Android.
49+
/// See {@link DocumentBuilderFactory#setFeature}
50+
logger.warn("Failed to enable XMLConstants.FEATURE_SECURE_PROCESSING, it's unsupported on" +
51+
" this platform.", e);
52+
}
4253
return documentBuilderFactory.newDocumentBuilder();
4354
} catch (ParserConfigurationException e) {
4455
throw new IllegalStateException(e);

0 commit comments

Comments
 (0)