This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch opennlp-2.x
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/opennlp-2.x by this push:
new c1ec87dd [2.x] OPENNLP-1785: Ignore ParserConfigurationException in
DocumentBuilder when setting XML secure processing feature unsupported on
Android (#892)
c1ec87dd is described below
commit c1ec87dd83d10155758cc234d5896b7cff4c0237
Author: soupslurpr <[email protected]>
AuthorDate: Sat Nov 22 05:29:06 2025 -0800
[2.x] OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder
when setting XML secure processing feature unsupported on Android (#892)
---
opennlp-tools/src/main/java/opennlp/tools/util/XmlUtil.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/XmlUtil.java
b/opennlp-tools/src/main/java/opennlp/tools/util/XmlUtil.java
index 93a4f3f3..c5adafb1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/XmlUtil.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/XmlUtil.java
@@ -24,10 +24,14 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
public class XmlUtil {
+ private static final Logger logger = LoggerFactory.getLogger(XmlUtil.class);
+
/**
* Create a new {@link DocumentBuilder} which processes XML securely.
*
@@ -38,7 +42,14 @@ public class XmlUtil {
public static DocumentBuilder createDocumentBuilder() {
try {
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
-
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ try {
+
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ } catch (ParserConfigurationException e) {
+ /// {@link XMLConstants.FEATURE_SECURE_PROCESSING} is not supported on
Android.
+ /// See {@link DocumentBuilderFactory#setFeature}
+ logger.warn("Failed to enable XMLConstants.FEATURE_SECURE_PROCESSING,
it's unsupported on" +
+ " this platform.", e);
+ }
return documentBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);