SAXNotRecognizedException: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' not recognized

cscan picture cscan · Aug 28, 2015 · Viewed 10.5k times · Source

I am receiving this error while unmarshalling a class. I'm using Amazon's mTurks along with Spring, Maven and (surprise, surprise) a xerces issue has reared it's head.

I've played with the POM in many different ways to try and iron out the problem but I can't seem to figure out the solution.

I'm using a mavenized version of mturks found here: https://github.com/tc/java-aws-mturk

I've explicitly excluded the xerces stuff from mturks:

<dependency>
    <groupId>com.amazon</groupId>
    <artifactId>java-aws-mturk</artifactId>
    <version>1.2.2</version>
    <exclusions>
        <exclusion>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
        </exclusion>
        <exclusion>
            <groupId>apache-xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>apache-xerces</groupId>
            <artifactId>resolver</artifactId>
        </exclusion>
        <exclusion>
            <groupId>apache-xerces</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

And explicitly included both xerces-impl and xml-api dependencies:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
</dependency>
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>

I've tried all four combinations with xercesImpl versions 2.9.1, 2.11.0 and xml-apis versions 1.4.01, 2.0.2 to no avail.

xercesImpl 2.11.0 and xml-api 2.0.2 leads to a different error:

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

How can I resolve this issue?

Answer

Dave B picture Dave B · Sep 30, 2016

This isn't specific to mturks, but here's a general approach for finding the xerces conflicts in eclipse to resolve the issue.

  1. Open your pom.xml in the eclipse editor and switch to the "Dependency Hierarchy" tab

  2. In the "Filter" box in the top right, type "xerces"

  3. The dependencies pulling in xercesImpl will be shown in the "Dependency Hierarchy" pane to the left

  4. Right click the offending xercesImpl entry and select "Exclude Maven Artifact...". This will update your pom with an exclusion which will resolve the conflict

  5. Be sure to press ctrl-s to save your pom changes

Dependency Hierarchy panel

Here's an example of the before and after in the raw pom.xml (eclipse did this for you in the above steps:

BEFORE

    <dependency>
      <groupId>junit-addons</groupId>
      <artifactId>junit-addons</artifactId>
      <version>1.4</version>
      <scope>test</scope>
    </dependency>

AFTER

    <dependency>
      <groupId>junit-addons</groupId>
      <artifactId>junit-addons</artifactId>
      <version>1.4</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
            <artifactId>xercesImpl</artifactId>
            <groupId>xerces</groupId>
        </exclusion>
      </exclusions>
    </dependency>

With this simple change, you can avoid the "access is not allowed due to restriction set..." error without resorting to JRE modifications or global settings