JDK-6236727 : XSLTC never stops resolving imported stylesheets when outer stylesheet is a DOMSource
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-03-07
  • Updated: 2012-04-24
  • Resolved: 2005-05-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.3.0 1.6Fixed
Description
I have a stylesheet, outer.xsl, that includes another stylesheet, inner.xsl,
via the xsl:include construct.  If I provide my own URIResolver and attempt
to compile outer.xsl from a DOMSource then XSLTC loops forever, repeatedly
resolving inner.xsl but never actually making any progress.

-- Bug.java --
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;


public class Bug {

    private static URIResolver resolver = new URIResolver() {
	    private int n = 0;
	    public Source resolve(String href, String base)
		throws TransformerException
	    {
		System.err.println("resolve " + href);
		if (n++ > 10) {
		    System.err.println("Test failed");
		    System.exit(1);
		}
		return new StreamSource(Bug.class.getResourceAsStream(href));
	    }
	};

    private static Document load(InputStream in)
	throws IOException
    {
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	dbf.setNamespaceAware(true);
	try {
	    DocumentBuilder db = dbf.newDocumentBuilder();
	    return db.parse(in);
	} catch (Exception x) {
	    throw new RuntimeException(x);
	}
    }

    public static void main(String[] args) throws Exception {

	boolean workaround = args.length > 0;

	TransformerFactory tff = TransformerFactory.newInstance();
	tff.setURIResolver(resolver);

	InputStream xin
	    = new BufferedInputStream(new FileInputStream("outer.xsl"));

	Templates tt = null;
	if (workaround)
	    tt = tff.newTemplates(new StreamSource(xin));
	else
	    tt = tff.newTemplates(new DOMSource(load(xin)));
	Transformer tf = tt.newTransformer();

    }

}

-- outer.xsl --
<s:stylesheet xmlns:s="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <s:include href="inner.xsl"/>
</s:stylesheet>

-- inner.xsl --
<s:stylesheet xmlns:s="http://www.w3.org/1999/XSL/Transform" version="1.0"/>


If I use a StreamSource rather than a DOMSource to read outer.xsl then this
problem does not occur.

This bug is reproducible in Tiger, in 5.0u2, and in Mustang b26.

###@###.### 2005-03-07 04:06:07 GMT

integrated in tag JWSDP-1_6-b08
###@###.### 2005-05-02 23:03:21 GMT

Comments
WORK AROUND Use a StreamSource rather than a DOMSource to read the outer stylesheet. ###@###.### 2005-03-07 04:06:07 GMT
07-03-2005

EVALUATION xmlReader needs to be cleared once the inner stylesheet is resolved. The following fix has been added to org.apache.xalan.xsltc.trax.Util.java. Fix patch provided by Santiago. Index: Util.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/Util.java,v retrieving revision 1.10 diff -r1.10 Util.java 150a151 > xsltc.setXMLReader(null); // Clear old XML reader ###@###.### 2005-04-14 06:41:56 GMT ###@###.### 2005-04-14 06:48:18 GMT
07-03-2005