This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/main by this push:
     new 3074bada OPENNLP-1785: Ignore ParserConfigurationException in 
DocumentBuilder when setting XML secure processing feature unsupported on 
Android
3074bada is described below

commit 3074badab635fc0f0dcef3d8a8f8d1d04c80737f
Author: soupslurpr <[email protected]>
AuthorDate: Sat Nov 22 05:29:06 2025 -0800

    OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when 
setting XML secure processing feature unsupported on Android
---
 .../src/main/java/opennlp/tools/util/XmlUtil.java           | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/XmlUtil.java 
b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/XmlUtil.java
index 93a4f3f3..c5adafb1 100644
--- a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/XmlUtil.java
+++ b/opennlp-core/opennlp-runtime/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);

Reply via email to