You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2002/03/08 11:23:23 UTC

DO NOT REPLY [Bug 6981] New: - XALAN throws EmptyStackException every two runs in a servlet

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6981>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6981

XALAN throws EmptyStackException every two runs in a servlet

           Summary: XALAN throws EmptyStackException every two runs in a
                    servlet
           Product: XalanJ2
           Version: 2.2.0
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Xalan
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: j.newald@i-views.de


I have a simple XML document, a simple XSLT stylesheet and a simple testing
servlet (actually the real files are significantly more complex, but I reduced
it on the simplest structure that causes the error).

The behaviour is that when I start the servlet and run the transformation the
first time, everything works fine - the output should be:

aaa bbb ccc sub bbb ccc 

The second request results into an EmptyStackException thrown in the deepness of
XALAN. See this Stacktrace:

javax.xml.transform.TransformerException: java.util.EmptyStackException

	at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1230)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:642)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1092)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1070)

	at
com.iviews.test.XALANEmptyStackExcpetionTestServlet.doGet(XALANEmptyStackExcpetionTestServlet.java:42)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

	at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)

	at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)

	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)

	at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)

	at java.lang.Thread.run(Thread.java:484)

---------

java.util.EmptyStackException

	at java.util.Stack.peek(Stack.java:82)

	at java.util.Stack.pop(Stack.java:64)

	at org.apache.xpath.XPathContext.popContextNodeList(XPathContext.java:682)

	at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1179)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:642)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1092)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1070)

	at
com.iviews.test.XALANEmptyStackExcpetionTestServlet.doGet(XALANEmptyStackExcpetionTestServlet.java:42)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

	at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)

	at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)

	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)

	at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)

	at java.lang.Thread.run(Thread.java:484)


The third request runs normal again, the fourth fails and so on.
The error does not appear, if I remove a certain xsl:sort statement (see xslt file).

Though the problem is quite annoying, somehow it seems to me an interesting
behaviour. I tested all the last versions of XALAN and XERCES with the same
result. If I run a simple java application that just does the transformation few
times, no exception is thrown. My servlet container is tomcat 3.1 and 3.2

Regards Jonny Newald

XML document EmptyStackExceptionTest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Test>
   <Config>
      <ItemConfig/>
      <SubtreeConfig>
         <Config>
            <ItemConfig/>
         </Config>
      </SubtreeConfig>
   </Config>
   <Response>
      <Item>
         <Name>ccc</Name>
      </Item>
      <Item>
         <Name>bbb</Name>
      </Item>
      <Item>
         <Name>aaa</Name>
      </Item>
      <Subtree>
         <Name>sub</Name>
         <Item>
            <Name>bbb</Name>
         </Item>
         <Item>
            <Name>ccc</Name>
         </Item>
      </Subtree>
   </Response>
</Test>

XSLT stylesheet EmptyStackExceptionTest.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
   <xsl:output method="text" version="1.0" encoding="ISO-8859-1"
omit-xml-declaration="yes"/>

   <xsl:template match="/Test">
      <xsl:apply-templates select="Config">
         <xsl:with-param name="data" select="Response"/>
      </xsl:apply-templates>
   </xsl:template>
   
   <xsl:template match="Config">
      <xsl:param name="data" select="/.."/>

      <xsl:apply-templates select="ItemConfig | SubtreeConfig">
         <xsl:with-param name="data" select="$data"/>
      </xsl:apply-templates>
   </xsl:template>

   <xsl:template match="ItemConfig">
      <xsl:param name="data" select="/.."/>
      
      <xsl:for-each select="$data/Item">
         <!--
            To bad, XALAN throws every two runs a java.util.EmptyStackException,
            if this xsl:sort statement is activated
         -->
         <xsl:sort select="Name" order="ascending"/>
         <xsl:value-of select="Name"/>
         <xsl:text> </xsl:text>
      </xsl:for-each>
   </xsl:template>

   <xsl:template match="SubtreeConfig">
      <xsl:param name="data" select="/.."/>

      <xsl:variable name="me" select="."/>
      <xsl:for-each select="$data/Subtree">
         <xsl:sort select="Name" order="ascending"/>

         <xsl:value-of select="Name"/><xsl:text> </xsl:text>
         <xsl:apply-templates select="$me/Config">
            <xsl:with-param name="data" select="."/>
         </xsl:apply-templates>
      </xsl:for-each>
   </xsl:template>

</xsl:stylesheet>


Testing Servlet:

package com.iviews.test;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.Document;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class XALANEmptyStackExcpetionTestServlet extends HttpServlet
{
   private static final TransformerFactory     tFactory =
TransformerFactory.newInstance();
   private static final DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();

   private Templates xsl;
   private Document doc;

   private static String xmlFileName = "Test/EmptyStackExceptionTest.xml";
   private static String xslFileName = "Test/EmptyStackExceptionTest.xslt";

   public void init(ServletConfig config) throws ServletException
   {
      super.init(config);
      try {
         doc = dFactory.newDocumentBuilder().parse(new
FileInputStream(config.getServletContext().getRealPath(xmlFileName)));
         xsl = tFactory.newTemplates(new StreamSource(new
File(config.getServletContext().getRealPath(xslFileName))));
      }
      catch (Exception e) {
         throw new ServletException(e);
      }
   }

   public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
   {
      response.setContentType("text/plain");
      PrintWriter out = response.getWriter();

      try {
         xsl.newTransformer().transform(new DOMSource(doc),new StreamResult(out));
      }
      catch (Exception e) {
         throw new ServletException(e);
      }
   }
}