Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2347

xpath expression containing attribute test followed by or and the preceding axis causes stack overflow.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.7
    • None
    • Xalan
    • None
    • Win XP, Xalan Java 2.7.0, java.version=1.5.0_06
    • PatchAvailable

    Description

      I have been getting a StackOverflowError when trying to perform an XSL transformation using Xalan 2.7.0 with a styleshhet I had written. I have simplified the the XSL and the problem seems to be related to an xpath expression used in an if, but I can't see anything wrong with it.
      I was using this xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <docdef>
      <region name="Main Region">
      <section id="2" name="section1">
      <frag id="1" name="part1" type="text">
      <p style="body" align="left" xml:space="preserve">first paragraph.</p>
      </frag>
      <frag id="2" name="next fragment" type="text">
      <p style="inherit" align="center" xml:space="preserve">Paragraph with a style of inherit but its own alignment , first in fragment.</p>
      <p style="inherit" xml:space="preserve"/>
      <p xml:space="preserve">Another paragraph</p>
      </frag>
      </section>
      </region>
      </docdef>

      with this xsl:
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" >
      <xsl:template match="p[@style='inherit']">
      <xsl:if test="not(preceding-sibling::) or preceding-sibling::[1] != preceding-sibling:[1]">
      <w>
      <w:pPr>
      <!-- This is the problem statement. The error does not occur if the '@align or' is removed from the start of the xpath.-->
      <xsl:if test="@align or preceding:[not(ancestor::table)][not(@style='inherit')][1]/@align">
      <xsl:element name="w:jc">
      <xsl:if test="@align">
      <xsl:attribute name="w:val"><xsl:value-of select="@align"/></xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@align)">
      <xsl:attribute name="w:val">
      <xsl:value-of select="preceding:[not(ancestor::table)][not(@style='inherit')][1]/@align"/>
      </xsl:attribute>
      </xsl:if>
      </xsl:element>
      </xsl:if>
      </w:pPr>
      <xsl:apply-templates/>
      </w>
      </xsl:if>
      </xsl:template>
      </xsl:stylesheet>

      The error message I get from Xalan is
      (Location of error unknown)XSLT Error (java.lang.StackOverflowError): null
      Exception in thread "main" java.lang.RuntimeException
      at org.apache.xalan.xslt.Process.doExit(Process.java:1153)
      at org.apache.xalan.xslt.Process.main(Process.java:1126)

      If I do the transformation within XMLSpy it does not report any errors so it seems to be something to do with Xalan.

      I have tried enabling various tracing options, see output below, but I get no additional output.

      C:\xalan\xalan-j_2_7_0>java -Xmx128M -cp c:\xalan\xalan-j_2_7_0\xalan.jar;c:\xal
      an\xalan-j_2_7_0\xml-apis.jar;c:\xalan\xalan-j_2_7_0\xercesImpl.jar org.apache.x
      alan.xslt.Process -TT -in test.xml -xsl test.xsl -out out.xml

      (Location of error unknown)XSLT Error (java.lang.StackOverflowError): null
      Exception in thread "main" java.lang.RuntimeException
      at org.apache.xalan.xslt.Process.doExit(Process.java:1153)
      at org.apache.xalan.xslt.Process.main(Process.java:1126)

      I also tried -TG, -TS and -TTC and all give the same result as above.
      The results of running environement check are shown below.

              • BEGIN writeEnvironmentReport($Revision: 1.29 $): Useful stuff found: ----
                version.DOM.draftlevel=2.0fd
                java.class.path=c:\xalan\xalan-j_2_7_0\xalan.jar;c:\xalan\xalan-j_2_7_0\xml-apis.jar;c:\xalan\xalan-j_2_7_0\xercesImpl.jar
                version.JAXP=1.1 or higher
                java.ext.dirs=C:\Program Files\Java\jre1.5.0_06\lib\ext
                version.xerces2=Xerces-J 2.7.1
                version.xerces1=not-present
                version.xalan2_2=Xalan Java 2.7.0
                version.xalan1=not-present
                version.ant=not-present
                java.version=1.5.0_06
                version.DOM=2.0
                version.crimson=not-present
                sun.boot.class.path=C:\Program Files\Java\jre1.5.0_06\lib\rt.jar;C:\Program Files\Java\jre1.5.0_06\lib\i18n.jar;C:\Program Files\Java\jre1.5.0_06\lib\sunrsasign.jar;C:\Program Files\Java\jre1.5.0_06\lib\jsse.jar;C:\Program Files\Java\jre1.5.0_06\lib\jce.jar;C:\Program Files\Java\jre1.5.0_06\lib\charsets.jar;C:\Program Files\Java\jre1.5.0_06\classes
              • BEGIN Listing XML-related jars in: foundclasses.java.class.path ----
                xalan.jar-path=c:\xalan\xalan-j_2_7_0\xalan.jar
                xml-apis.jar-apparent.version=xml-apis.jar from head branch of xml-commons, tag: xml-commons-external_1_3_02
                xml-apis.jar-path=c:\xalan\xalan-j_2_7_0\xml-apis.jar
                xercesImpl.jar-apparent.version=xercesImpl.jar from Xerces-J-bin.2.7.1
                xercesImpl.jar-path=c:\xalan\xalan-j_2_7_0\xercesImpl.jar
                • END Listing XML-related jars in: foundclasses.java.class.path -----
                  version.SAX=2.0
                  version.xalan2x=Xalan Java 2.7.0
                • END writeEnvironmentReport: Useful properties found: -----
      1. YAHOO! Your environment seems to be OK.

      I have also managed to get the error with a different but similar Xpath expression. It seems to be a problem when it starts with "@align or preceding" an attribute test followed by the ancestor axis does not seem to cause a problem and if I remove the '@align or' from the begining and break it up into multiple xsl:if statements it is okay.
      I believe it is happening when the stylesheet it first passed before it actually starts the transformation.

      Attachments

        1. patch.j2347.txt
          0.6 kB
          Henry Zongaro
        2. j2347.tiny.xsl
          0.3 kB
          Henry Zongaro

        Issue Links

          Activity

            People

              zongaro@ca.ibm.com Henry Zongaro
              robe Robert Eaton
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: