Transforming a docbook document with Xalan ends up with a java.lang.StackOverflowError.
I am using Xalan-J version 2.7.1, docbook-xsl version 1.74.0, docbook-xml version 4.5.
The following small Java program ilustrates this.
Setting NUMROWS to a lower value makes the error disappear. However, I need this program to run with large tables too.
Scaleability is a high priority issue. I think something has been solved in a recursive way, which makes the transformation of large tables not scaleable.
I am running the program under Eclipse with standard stack size settings. The error also appears in other environments.
package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
*
* Xalan Processor
*
*/
public class XalanProcessor {
public static int NUMROWS = 700;
public static final String CHARSETNAME = "utf-8";
public static TransformerFactory tFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", XalanProcessor.class.getClassLoader());
public static void transform(Source src, URL xsltUri, OutputStream out, final OutputStream debug)
throws TransformerConfigurationException, TransformerException {
// Setup Transformer
Source xsltSrc = new StreamSource(xsltUri.toExternalForm());
Transformer transformer = tFactory.newTransformer(xsltSrc);
if (debug != null) {
try {
debug.write("newTransformer successful".getBytes(CHARSETNAME));
} catch (IOException e){
}
}
Result res = new StreamResult(out);
// Start the transformation process
transformer.transform(src, res);
}
private static File _reportFile = null;
private static OutputStream _reportStream;
private static File _transformedFile;
public static void main(String[] args) {
URL xsltUri = null;
OutputStream _transformedStream = null;
OutputStream _debugStream = null;
try {
_reportFile = File.createTempFile("Report", ".tmp");
_reportStream = new FileOutputStream(_reportFile);
String string = "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.5//EN\"\n" +
"\"file:\\Documents and Settings\\hans\\workspace1\\xalan-fop-stacktest\\formatting\\docbook-xml-4.5\\docbookx.dtd\">\n" +
"<book>\n" +
"<title>Report</title>\n" +
"\n" +
"<chapter>\n" +
"<title>First Section</title>\n" +
"\n" +
"<para>Some para.</para>\n" +
"<para>Some list:<itemizedlist>\n" +
"<listitem><para>A listitem</para></listitem>\n" +
"</itemizedlist>\n" +
"</para>\n" +
"<sect1><title>Sect title</title><table>\n" +
"<title>Table title</title>\n" +
"<tgroup cols=\"1\"><colspec colname=\"leftcol\"/><colspec colnum=\"1\" colname=\"rightcol\"/><spanspec spanname=\"allcolumns\" namest=\"leftcol\" nameend=\"rightcol\"/>\n" +
"<thead>\n" +
"<row>\n" +
"<entry><![CDATA[name]]></entry>\n" +
"</row>\n" +
"</thead>\n" +
"<tbody>\n";
_reportStream.write(string.getBytes(CHARSETNAME));
for (int i = 1; i <= NUMROWS; i++) {
string = "<row>\n" +
"<entry><![CDATA[name"+i+"]]></entry>\n" +
"</row>\n" ;
_reportStream.write(string.getBytes(CHARSETNAME));
}
string = "</tbody>\n" +
"</tgroup>\n" +
"</table>\n" +
"</sect1>\n" +
"</chapter>\n" +
"</book>\n";
_reportStream.write(string.getBytes(CHARSETNAME));
_reportStream.close();
_transformedFile = File.createTempFile("Output", ".fo");
_transformedStream = new FileOutputStream(_transformedFile);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
xsltUri = new URL("file:\\Documents and Settings\\hans\\workspace1\\xalan-fop-stacktest\\formatting\\docbook-xsl-1.74.0\\fo\\docbook.xsl");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
try {
XalanProcessor.transform(new StreamSource(_reportFile), xsltUri, _transformedStream, _debugStream);
_transformedStream.close();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Done");
}
}
I can reproduce the error with Java 1.6.0_01 on Windows XP. However, it works when the stack size is increased (using "-Xss1024k" on the command line).
This is a known issue without any obvious XSLT solution. See:
http://www.oasis-open.org/archives/docbook-apps/200703/msg00194.html
https://sourceforge.net/tracker/index.php?func=detail&aid=1675672&group_id=21935&atid=373747
Dear Mauritz Jeanson,
Thank you for your comment.
The big question is: will it keep on working with an increased stack size, when you also increase NUMROWS?
In other words: I can not keep on increasing the stack size if the table grows. The 700 value for NUMROWS was only meant as an example for this demonstration, showing the bounds of the stack.
I understand this is a known issue, but in my real application I am not able to bound the table size.
Regards,
Hans van Rijswijk
Netherlands.
> The big question is: will it keep on working with an
> increased stack size,
> when you also increase NUMROWS?
Why don't you test it yourself?
I increased NUMROWS to 1300, and it worked with a stack size of 2048k.
> In other words: I can not keep on increasing the stack size
> if the table
> grows. The 700 value for NUMROWS was only meant as an example for this
> demonstration, showing the bounds of the stack.
> I understand this is a known issue, but in my real
> application I am not
> able to bound the table size.
OK, I'm sure you have good reasons for this, but I don't think I can do much more.
Here is another bug about the same issue with more background information:
https://sourceforge.net/tracker/index.php?func=detail&aid=1211477&group_id=21935&atid=373747
It is of course possible that someone could come up with a solution or a workaround if you described the requirements and the application in more detail. However, this bug tracker is not a good place for discussions. You are welcome to ask for feedback on the docbook-apps mailing list (which has a much larger readership).
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).