NullPointerException in com.xmlcalabash.util.XProcURIResolver #35

raducoravu opened this Issue Mar 14, 2012 · 5 comments


None yet

2 participants


I have an XProc with code like this:
<p:xsl-formatter content-type="application/pdf">
<p:with-option name="href" select="$pdf-file"></p:with-option>
<p:with-param name="UserConfig" select="$fop-config"/>

which tries to generate PDF using Apache FOP.

The FOP configuration file looks like this:

<fop version="1.0">
<renderer mime="application/pdf">

When transforming, the output fails with a message like:

Failed to process FO document with FOP null

which is actually generated by:

Caused by: java.lang.NullPointerException
at$Parser.parse(Unknown Source)
at Source)
at com.xmlcalabash.util.XProcURIResolver.resolve(Unknown Source)
at org.apache.fop.apps.FOURIResolver.resolve(
at org.apache.fop.apps.FopFactory.resolveURI(
at org.apache.fop.apps.FOUserAgent.resolveURI(
at org.apache.fop.render.DefaultFontResolver.resolve(
at org.apache.fop.fonts.FontLoader.openFontUri(
at org.apache.fop.fonts.FontLoader.getFont(
at org.apache.fop.fonts.FontLoader.loadFont(
at org.apache.fop.fonts.LazyFont.load(
at org.apache.fop.fonts.LazyFont.getAscender(
at org.apache.fop.fonts.Font.getAscender(
at org.apache.fop.layoutmgr.BlockLayoutManager.initialize(
at org.apache.fop.layoutmgr.AbstractLayoutManager.getChildLM(

So the method:

public Source resolve(String href, String base) throws TransformerException {

receives a NULL base from Apache FOP and tries to make an URI out of it:


So you should take into account on the URIResolver the possibility of a NULL base.

The workaround is simple, a "./" can be specified in the configuration file in order for Apache FOP to also specify the base in the URI resolver and avoid the NPE.

One more improvement which would help debug such cases would be that in the method:

when an exception is caught, it should not be ignored but instead be provided as the cause of the thrown XProcException.

ndw commented Mar 15, 2012

I believe does include the underlying exception:

        try {
            out = new BufferedOutputStream(new FileOutputStream(output));
        } catch (XProcException e) {
            throw e;
        } catch (Exception e) {
            throw new XProcException(step.getNode(), "Failed to process FO document", e);
        } finally {

If you can provide a complete pipeline that demonstrates the NPE problem, I'll see what I can do.

I'm not sure what the right semantic is when the base is null.


Hi Norm,

About wrapping the original exception, I was referring to this part of the XSLFormatter:

    FoProcessor provider = null;
    for (String className : foClasses) {
        if (provider == null) {
            try {
                provider = (FoProcessor) Class.forName(className).newInstance();
            } catch (NoClassDefFoundError ncdfe) {
                provider = null;
            } catch (Exception e) {
              //THE NPE IS CAUGHT HERE...........................
                provider = null;

    if (provider == null) {
        throw new XProcException(step.getNode(), "Failed to instantiate FO provider");

About the approach in the XProcURIResolver when the base is NULL, the Xerces URI Resolver has the code something like:
if (base==null) {
url = new URL(uri);
result = url.toString();
} else {
URL baseURL = new URL(base);
url = (href.length()==0 ? baseURL : new URL(baseURL, uri));
result = url.toString();


ndw commented Mar 15, 2012

Ah. Ok. I'd already reworked part of that code in XSLFormatter which partially corrected the problem. I improved it some more :-)

And I attempted to do the Xerces compatible thing in resolve()


Thanks, Norm.

@ndw ndw closed this May 19, 2012
ndw commented May 19, 2012

I hope this is fixed now. Please reopen if it isn't.

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