1

Please note: Although there are several questions on SO that paste in a similar exception & stack trace, this question is definitely not a dupe of any of them, as I'm trying to understand where my classloading is going awry.

Hi, Java 8/Groovy 2.4.3/Eclipse Luna here. I'm using the BigIP iControl Java client (for controlling a powerful load balancer programmatically) which in turn uses Apache Axis 1.4. In its use of Axis 1.4 I am getting the following stacktrace (from Eclipse console):

Caught: javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
    at org.apache.axis.utils.XMLUtils.getDOMFactory(XMLUtils.java:221)
    at org.apache.axis.utils.XMLUtils.<clinit>(XMLUtils.java:83)
    at org.apache.axis.configuration.FileProvider.configureEngine(FileProvider.java:179)
    at org.apache.axis.AxisEngine.init(AxisEngine.java:172)
    at org.apache.axis.AxisEngine.<init>(AxisEngine.java:156)
    at org.apache.axis.client.AxisClient.<init>(AxisClient.java:52)
    at org.apache.axis.client.Service.getAxisClient(Service.java:104)
    at org.apache.axis.client.Service.<init>(Service.java:113)
    at iControl.LocalLBPoolLocator.<init>(LocalLBPoolLocator.java:21)
    at iControl.Interfaces.getLocalLBPool(Interfaces.java:351)
    at com.me.myapp.F5Client.run(F5Client.groovy:27)

Hmmm, let's have a look at that XMLUtils.getDOMFactory method:

private static DocumentBuilderFactory getDOMFactory() {
    DocumentBuilderFactory dbf;
    try {
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
    }
    catch( Exception e ) {
        log.error(Messages.getMessage("exception00"), e );
        dbf = null;
    }
    return( dbf );
}

OK, LN 221 is that call to DocumentBuilderFactory.newInstance() so let's have a look at it:

public static DocumentBuilderFactory newInstance() {
    return FactoryFinder.find(
        /* The default property name according to the JAXP spec */
        DocumentBuilderFactory.class, // "javax.xml.parsers.DocumentBuilderFactory"
        /* The fallback implementation class name */
        "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
}

The plot thickens! Now let's take a final look at FactoryFinder.find:

static <T> T find(Class<T> type, String fallbackClassName)
        throws FactoryConfigurationError
{
    final String factoryId = type.getName();
    dPrint("find factoryId =" + factoryId);

    // lots of nasty cruft omitted for brevity...


    // Try Jar Service Provider Mechanism
    T provider = findServiceProvider(type);
    if (provider != null) {
        return provider;
    }
    if (fallbackClassName == null) {
        throw new FactoryConfigurationError(
            "Provider for " + factoryId + " cannot be found");      // <<-- Ahh, here we go
    }

    dPrint("loaded from fallback value: " + fallbackClassName);
    return newInstance(type, fallbackClassName, null, true);
}

So if I'm interpreting this right, it's throwing the FactoryConfigurationError because it can't find the main "provider class" (whatever that means) and no fallback has been specified. But hasn't it?!? The call to FactoryFinder.find included the non-null "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl" string argument. This has me suspicious that something is really wonky with my classpath, and that I have a rogue DocumentBuilderFactory (not the one defined in rt.jar/javax/xml/parsers) somewhere in my code that is passing a NULL arg to this finder method.

But that doesn't make sense either, because Axis 1.4 doesn't appear (at least according to Maven repo) to have any dependencies...which means the only "provider" for javax.xml.* would be the rt.jar. Unless, perhaps, Eclipse is mucking things up somehow? I'm so confused, please help :-/


Update

This is definitely an Eclipse issue. If I package my app as an executable JAR and run it from the command line I don't get this exception.

smeeb
  • 22,487
  • 41
  • 197
  • 389

0 Answers0