Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenNLP: documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true) ParserConfigurationException

Tags:

java

android

xml

So i'm trying to use OpenNLP within Android Studio, but my application always throws a ParserConfigurationException within this body of code that is used by OpenNLP in their XmlUtil class, which that I am unable to modify:

public static DocumentBuilder createDocumentBuilder() {
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        return documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException var1) {
        throw new IllegalStateException(var1);
    }
}

documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); causes the application to throw a ParserConfigurationException.

Been stuck on this for about a week now and no luck, any tips for how I can get around this error?

like image 715
Keaton MacLeod Avatar asked Oct 27 '25 05:10

Keaton MacLeod


1 Answers

I had the same problem using version 1.9.1 of OpenNLP and I solved this by using version 1.6.0 instead. This is the latest version I've managed to get working.

dependencies {
  implementation 'org.apache.opennlp:opennlp-tools:1.6.0'
}

Downgrading was seamless since the models are the same and the public API is largely similar (at least for my use).


Full story: I was making a prototype with OpenNLP to use a TokenizerME and two NameFinderME -- for persons and locations. These are all the versions of OpenNLP I've tried (and failed with):

  • 1.9.1 and 1.9.0: failing with the ParserConfigurationException described in the OP
  • 1.8.0 and 1.7.0: both crash with an OutOfMemoryError when trying to load the NameFinderME
like image 68
David Ferrand Avatar answered Oct 28 '25 20:10

David Ferrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!