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=6854>.
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=6854

IntStack throws ArrayIndexOutOfBoundsException

           Summary: IntStack throws ArrayIndexOutOfBoundsException
           Product: XalanJ2
           Version: CurrentCVS
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xml.utils
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


In a complicated Cocoon2 pipeline, we get consistent error in IntStack. The 
same error cannot be recreated if we export our XML into a file and then run 
the stylesheet on it. But the good news is that the following patch works. 
Basically if the array index is less then zero, the code should throw an 
EmptyStackException. This is documented by the javadoc but not implemented in 
current cvs :(


Index: src/org/apache/xml/utils/IntStack.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/IntStack.java,v
retrieving revision 1.5
diff -d -u -b -B -w -u -r1.5 IntStack.java
--- src/org/apache/xml/utils/IntStack.java      21 Jun 2001 18:52:52 -0000
        1.5
+++ src/org/apache/xml/utils/IntStack.java      4 Mar 2002 17:51:50 -0000
@@ -145,7 +145,10 @@
    */
   public int peek()
   {
-    return m_map[m_firstFree - 1];
+    int index = m_firstFree - 1;
+    if(index < 0)
+        throw new EmptyStackException();
+    return m_map[index];
   }
 
   /**
@@ -157,7 +160,10 @@
    */
   public int peek(int n)
   {
-    return m_map[m_firstFree-(1+n)];
+      int index = m_firstFree-(1+n);
+      if(index < 0)
+          throw new EmptyStackException();
+      return m_map[index];
   }
 
   /**

Reply via email to