Skip to content

[2.x] OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android#892

Merged
mawiesne merged 1 commit intoapache:opennlp-2.xfrom
soupslurpr:opennlp-2.x-prevent-xml-crash-on-android
Nov 22, 2025
Merged

[2.x] OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android#892
mawiesne merged 1 commit intoapache:opennlp-2.xfrom
soupslurpr:opennlp-2.x-prevent-xml-crash-on-android

Conversation

@soupslurpr
Copy link
Contributor

@soupslurpr soupslurpr commented Nov 18, 2025

Hello! When trying to use POSTagger on Android, a ParserConfigurationException is thrown when OpenNLP tries to create a DocumentBuilder. It's thrown when the XML secure processing feature is set. I looked into it, and found out that the feature is not supported on Android.

You can view the comment saying it's not supported in the Android source code here: https://cs.android.com/android/platform/superproject/main/+/main:libcore/luni/src/main/java/javax/xml/parsers/DocumentBuilderFactory.java;l=310-312

I added ignoring the exception when setting that feature so the POSTagger works on Android. I tested it and it now works well.


Thank you for contributing to Apache OpenNLP.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions for build issues and submit an update to your PR as soon as possible.

@jzonthemtn
Copy link
Contributor

@soupslurpr Thanks for the contribution!

@soupslurpr soupslurpr force-pushed the opennlp-2.x-prevent-xml-crash-on-android branch from a9318cd to 176d908 Compare November 18, 2025 13:24
@rzo1 rzo1 requested a review from mawiesne November 18, 2025 13:35
@rzo1 rzo1 changed the title ignore ParserConfigurationException when setting XML secure processing feature in DocumentBuilder as it's unsupported on Android OPENNLP-1785 - Ignore ParserConfigurationException when setting XML secure processing feature in DocumentBuilder as it's unsupported on Android Nov 18, 2025
@mawiesne mawiesne changed the title OPENNLP-1785 - Ignore ParserConfigurationException when setting XML secure processing feature in DocumentBuilder as it's unsupported on Android OPENNLP-1785 - Ignore ParserConfigurationException when setting XML secure processing feature in DocumentBuilder unsupported on Android Nov 18, 2025
@mawiesne mawiesne changed the title OPENNLP-1785 - Ignore ParserConfigurationException when setting XML secure processing feature in DocumentBuilder unsupported on Android OPENNLP-1785 - Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android Nov 19, 2025
@mawiesne mawiesne changed the title OPENNLP-1785 - Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android Nov 21, 2025
Copy link
Contributor

@mawiesne mawiesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soupslurpr Thx for the contribution. I've left minor comments for polishing the PR.

…ocessing feature in DocumentBuilder as it's unsupported on Android
@soupslurpr soupslurpr force-pushed the opennlp-2.x-prevent-xml-crash-on-android branch from 176d908 to 2e4689a Compare November 22, 2025 00:54
@soupslurpr
Copy link
Contributor Author

@mawiesne Thanks for the feedback! I made the requested changes. Looks good now?

@soupslurpr soupslurpr requested a review from mawiesne November 22, 2025 01:13
Copy link
Contributor

@rzo1 rzo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Would you mind opening the same change against main too? :)

Copy link
Contributor

@mawiesne mawiesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soupslurpr Thx for the quick adjustments and this important contribution. Pls, check @rzo1's comment targeting the main branch (3.x)

@mawiesne mawiesne changed the title OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android [2.x] OPENNLP-1785: Ignore ParserConfigurationException in DocumentBuilder when setting XML secure processing feature unsupported on Android Nov 22, 2025
@mawiesne mawiesne merged commit c1ec87d into apache:opennlp-2.x Nov 22, 2025
10 checks passed
@soupslurpr
Copy link
Contributor Author

Sure thing, here's the PR targeting the main branch: #896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants