You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Frank E. Weiss" <fr...@well.com> on 2002/02/02 23:31:34 UTC

Reusing stylesheet more that 2 times raises exceptions

This problem came from using Ant's Style task after I upgrading an existing Ant project to use Xalan-J-2.2.0 after using
2.0.1. I isolated the problem by modifying the trax examples code (code appended). The exceptions are sensitive to the
order and number of input documents that are trying to be transformed with a stylesheet reuse. Also, the stylesheet
imports other stylesheets.

I'm new to this list, but I did scan the bug reports for similar problems. Anybody have suggestions as to how to solve
this problem?

Here are the exceptions that are encountered in the "community" test case:

EXCEPTION:
javax.xml.transform.TransformerException: java.lang.ArrayIndexOutOfBoundsException
        at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1741)
...
---------
java.lang.ArrayIndexOutOfBoundsException
        at org.apache.xalan.transformer.ResultTreeHandler.flushElem(ResultTreeHandler.java:868)
...
---------
java.lang.ArrayIndexOutOfBoundsException
        at org.apache.xml.utils.SuballocatedIntVector.elementAt(SuballocatedIntVector.java:453)


Here's the modified Trax Examples source code:
==========================
 public static void exampleTransformerReuse(Vector sources, String xslID)
 throws TransformerException, TransformerConfigurationException
 {
  TransformerFactory tfactory = TransformerFactory.newInstance();
  Transformer transformer = tfactory.newTransformer(new StreamSource(baseDir + xslID));
  for (Enumeration e=sources.elements(); e.hasMoreElements(); )
  {
   String sourceID = (String)e.nextElement();
   System.out.println("\n=========" + sourceID + "\n");
   transformer.transform( new StreamSource(baseDir + sourceID),
           new StreamResult(destDir + sourceID));

  }
 }




Update: Reusing stylesheet more that 2 times raises exceptions

Posted by "Frank E. Weiss" <fr...@well.com>.
The problem is, to refresh this thread:

Using Xalan-J-2.2.0 with JDK1.3.1 on W2K, I'm getting NullPointer and/or StringArrayIndexOutOfBounds exceptions after
transforming at least two documents and reusing the stylesheet. The number and order of documents transformed affects
how many transformations succeed before the exceptions. Works OK with Xalan-J-2.0.1.

I've dug into this problem some more and have narrowed it down (without absolute certainty) to a combination of:

Reuse stylesheet (with or without template)
AND
use document() to access a second input document
AND
use a recursive template (on the second input document)

I noticed  another post with recursive template problem. It didn't seem to match the problem I'm having, but there may
be a remote connection.

Sometimes I've seen other exceptions such as Unknown error in XPath or some DTM errors, while hacking the stylesheet to
isolate the problem.

I'll continue my sleuthing, but hope someone may have some info from running into a similar scenario.




Re: Reusing stylesheet more that 2 times raises exceptions

Posted by douglas d <do...@speakeasy.org>.
Hi,
    I am doing the same thing, and in my test harness I reused the
Transformer several hundred times.
    After each transformation, you need to clear out the transformer. Look
at the javadoc, but I think the call is clearParameters()
    If you are working in a multithreaded enviroment, you will also need to
synchronize on the transformer.

for (Enumeration e=sources.elements(); e.hasMoreElements(); )
{
      String sourceID = (String)e.nextElement();
      System.out.println("\n=========" + sourceID + "\n");

    synchronized(transformer)
    {

      transformer.transform( new StreamSource(baseDir + sourceID),
              new StreamResult(destDir + sourceID));

       // clear here
       transformer.clearParameters();

    }

}

    easy,
    douglas d



----- Original Message -----
From: "Frank E. Weiss" <fr...@well.com>
To: <xa...@xml.apache.org>
Sent: Saturday, February 02, 2002 2:31 PM
Subject: Reusing stylesheet more that 2 times raises exceptions


> This problem came from using Ant's Style task after I upgrading an
existing Ant project to use Xalan-J-2.2.0 after using
> 2.0.1. I isolated the problem by modifying the trax examples code (code
appended). The exceptions are sensitive to the
> order and number of input documents that are trying to be transformed with
a stylesheet reuse. Also, the stylesheet
> imports other stylesheets.
>
> I'm new to this list, but I did scan the bug reports for similar problems.
Anybody have suggestions as to how to solve
> this problem?
>
> Here are the exceptions that are encountered in the "community" test case:
>
> EXCEPTION:
> javax.xml.transform.TransformerException:
java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.
java:1741)
> ...
> ---------
> java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xalan.transformer.ResultTreeHandler.flushElem(ResultTreeHandler.j
ava:868)
> ...
> ---------
> java.lang.ArrayIndexOutOfBoundsException
>         at
org.apache.xml.utils.SuballocatedIntVector.elementAt(SuballocatedIntVector.j
ava:453)
>
>
> Here's the modified Trax Examples source code:
> ==========================
>  public static void exampleTransformerReuse(Vector sources, String xslID)
>  throws TransformerException, TransformerConfigurationException
>  {
>   TransformerFactory tfactory = TransformerFactory.newInstance();
>   Transformer transformer = tfactory.newTransformer(new
StreamSource(baseDir + xslID));
>   for (Enumeration e=sources.elements(); e.hasMoreElements(); )
>   {
>    String sourceID = (String)e.nextElement();
>    System.out.println("\n=========" + sourceID + "\n");
>    transformer.transform( new StreamSource(baseDir + sourceID),
>            new StreamResult(destDir + sourceID));
>
>   }
>  }
>
>
>