Search code examples
javaspringxercesoc4j

Weird Xerces method access error


I've tried this on both Xerces 2.9.1, and Xerces-J-2.11.0 with the same results.

I'm writing a Spring3 Webflow app, using Xerces for XML parsing. When deploying the EAR, I get an issue

Caused by: java.lang.IllegalAccessError: tried to access method org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Lorg/apache/xerces/jaxp/DocumentBuilderFactoryImpl;Ljava/util/Hashtable;Ljava/util/Hashtable;)V from class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
    at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:99)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 30 more

If I trace the code in a Java Decompilor, in xercesImpl.jarI can see the DocumentBuilderFactoryImpl.setAttribute() call tries to create a new DocumentBuilderImpl, this seems to be the cause of the IllegalAccessError. The constructor for the DocumentBuilderImpl has default (package) access, but both DocumentBuilderImpl, and DocumentBuilderFactoryImpl reside in the same package (org.apache.xerces.jaxp).

As far as I'm aware, there is no SecurityManager active at the time of the error (and I'm not even sure whether the SecurityManager would affect method access permissions, I thought it was just for class loading, and resource access permissions).

Any ideas what I can do (short of recompiling the xerces JAR with less restrictive access permissions, I'd like to sort out the root of the problem, not work around it!, I'd also prefer to use the standard JARs where I can).

I should mention, I'm using Spring 3.0.5, OC4J 10.0.3.5.0 (with the work-around in place to use the Xerces XML parser instead of the Oracle XML parser), and Java 1.6.0-21.

Thanks Graham


Solution

  • You're having a class-loader issue because you're bundling Xerxes; and Java 1.6 already bundles Xerces.

    I've had many "unexpected" problems with xerces, activation, and a few other libraries that we external before java 1.6 and are now bundled in the JRE. :(