As is often the case with me, my initial report on this issue was hasty. However, it does still appear to me that there is an issue.

It looks like this is what is occurring:
1. When Saxon sees a custom config file, it appears to examine (perhaps for optimization purposes) some aspects of the stylesheet that it might not otherwise examine, including templates that may never be called.
2. When it does this examination/optimization, one of the user-defined functions in my import file was causing it to throw the exception I mentioned earlier.

I've localized the particular snippet in this function it does not like.  Two of the elements in this template has @fill attributes set using an AVT.  The expression used is:

fill="{concat('rgb(',round(255 * $colors[($pos -1) * 3 + 1]),',',round(255 * $colors[($pos -1) * 3 + 2]),',',round(255 * $colors[($pos -1) * 3 + 3]),')')}"


For whatever reason, Saxon throws an exception upon examining this piece even though the template never runs. However it *only* throws an exception when it is given a custom configuration file.

The entire template is given below, it creates a souped-up pie chart using svg:

<xsl:template name="pie">
        <xsl:param name="title"/>
        <xsl:param name="radius"/>
        <xsl:param name="entries" as="node()"/>
        <xsl:param name="note" as="xs:string?"/>
        <xsl:variable name="total" select="sum($entries/data/item/@value)"/>
        <xsl:variable name="cx" select="$radius + 35"/>
        <xsl:variable name="cy" select="$radius + 35"/>
        <xsl:text>
</xsl:text>
        <xsl:variable name="colors" select="random:random-sequence(3*count($entries/data/item))"/>
        <div style="padding-top:50px; padding-bottom:30px">
            <table border="10" frame="box" align="center" rules="all" cellpadding="10">
                <tr>
                    <td colspan="4">
                        <font size="5">
                            <center>
                                <xsl:value-of select="$title"/>
                            </center>
                        </font>
                    </td>
                </tr>
                <tr>
                    <td rowspan="{count($entries/data/item) + 1}">
                        <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
                            height="{2*$radius + 70}" width="{2*$radius + 100}">
                            <xsl:for-each select="$entries/data/item">
                                <xsl:variable name="pos" select="position()"/>
                                <xsl:variable name="prev"
                                    select="sum(preceding-sibling::item/@value)"/>
                                <path
                                    d="{concat('M',$cx,' ',$cy,' l',$radius*math:cos(2*3.14159 *$prev div $total),' ',$radius*math:sin(2*3.14159*$prev div $total),' A',$radius,' ',$radius,' 0 ',if (@value div $total gt 0.5) then 1 else 0 ,' 1 ',$cx + $radius*math:cos(2*3.14159*($prev + xs:decimal(@value)) div $total),' ',$cy + $radius*math:sin(2*3.14159*($prev + xs:decimal(@value)) div $total),' z')}"
                                    fill="{concat('rgb(',round(255 * $colors[($pos -1) * 3 + 1]),',',round(255 * $colors[($pos -1) * 3 + 2]),',',round(255 * $colors[($pos -1) * 3 + 3]),')')}"
                                    stroke="black" stroke-width="1"   
                                />
                            </xsl:for-each>
                        </svg>
                       
                    </td>
                    <td colspan="3" align="center">
                        <font size="4">Legend</font>
                    </td>
                </tr>
                <xsl:for-each select="$entries/data/item">
                    <xsl:variable name="pos" select="position()"/>
                    <tr>
                        <td>
                            <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
                                height="{round(2 * $radius div count($entries/data/item))-10}"
                                width="{round($radius div 2)}">
                                <rect x="3" y="3" width="{round($radius div 2 - 6)}"
                                    height="{round(2 * $radius div count($entries/data/item) - 14)}"
                                    fill="{concat('rgb(',round(255 * $colors[($pos -1) * 3 + 1]),',',round(255 * $colors[($pos -1) * 3 + 2]),',',round(255 * $colors[($pos -1) * 3 + 3]),')')}"
                                />
                            </svg>
                        </td>
                        <td align="center">
                            <xsl:value-of select="current()/@label"/>
                        </td>
                        <td align="center" width="{round($radius div 3)}">
                            <xsl:value-of
                                select="concat(round(100 * current()/@value div $total),'%')"/>
                        </td>
                    </tr>
                </xsl:for-each>
                <xsl:if test="boolean($note)">
                    <tr>
                        <td colspan="4">
                            <xsl:value-of select="$note"/>
                        </td>
                    </tr>
                </xsl:if>
            </table>
        </div>
    </xsl:template>





On Sun, Jun 23, 2013 at 3:30 AM, David Rudel <fwqhgads@gmail.com> wrote:
I was testing out Saxon 9.5.0.2 in the current oxYgen developer release and found that Saxon was throwing the following error:

java.lang.ArrayIndexOutOfBoundsException


The more detailed version was:

net.sf.saxon.trans.XPathException: java.lang.ArrayIndexOutOfBoundsException
    at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:475)
    at net.sf.saxon.style.PrincipalStylesheetModule.compileStylesheet(Unknown Source)
    at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(Unknown Source)
    at net.sf.saxon.PreparedStylesheet.prepare(Unknown Source)
    at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:142)
    at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:97)
    at ro.sync.xml.transformer.b.f(Unknown Source)
    at ro.sync.xml.transformer.b.p(Unknown Source)
    at ro.sync.xml.transformer.b.v(Unknown Source)
    at ro.sync.xml.transformer.b.db(Unknown Source)
    at ro.sync.xml.transformer.b.x(Unknown Source)
    at ro.sync.exml.editor.xmleditor.fc.kup(Unknown Source)
    at ro.sync.exml.editor.xmleditor.fc.bvp(Unknown Source)
    at ro.sync.exml.editor.xmleditor.fc$4.kwc(Unknown Source)
    at ro.sync.ui.application.gb.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException
---------
java.lang.ArrayIndexOutOfBoundsException

A bit of testing indicated the problem stemmed from my using a custom config file. However, it took quite a bit of testing to determine what was actually causing the problem. It appears the issue is that my config file did not explicitly set the uriResolver attribute of the global element in the config file.

The bare config file below does not cause an error:

<configuration xmlns="http://saxon.sf.net/ns/configuration" edition="EE">
    <global   uriResolver="net.sf.saxon.StandardURIResolver"
  />
</configuration>

However, it seems that any config file that does *not* explicitly render this attribute does lead to the exception being thrown.

-David

--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.