minchau     2003/08/12 16:04:30

  Modified:    java/src/org/apache/xalan/xsltc/compiler LiteralElement.java
  Log:
  
  PR: bugzilla 19972    
  Submitted by: William Lee ([EMAIL PROTECTED])
  Reviewed by:  Brian Minchau and Gordon Chui
  
  The code loops over elements in a Vector, incrementing the index j.
  Some elements should not be processed so they were removed from the Vector.
  The removal of element "j" shifted all higher elements down and made the
  Vector 1 shorter.  So removal of an element and incrementing "j" actually caused
  elements to be skipped.
  
  It is not quite clear why the element is being removed from the Vector rather
  than just skipped over. For safety sake an iteration over the loop either removes an
  element, or increments "j", but not both in the same iteration.
  
  Revision  Changes    Path
  1.23      +16 -6     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
  
  Index: LiteralElement.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- LiteralElement.java       25 Jul 2003 20:04:20 -0000      1.22
  +++ LiteralElement.java       12 Aug 2003 23:04:30 -0000      1.23
  @@ -377,12 +377,22 @@
        il.append(methodGen.startElement());
   
        // The value of an attribute may depend on a (sibling) variable
  -     for (int i = 0; i < elementCount(); i++) {
  -         final SyntaxTreeNode item = (SyntaxTreeNode) elementAt(i);
  -         if (item instanceof Variable) {
  -             item.translate(classGen, methodGen);
  -             removeElement(item);    // avoid translating it twice
  +    int j=0;
  +    while (j < elementCount())
  +    {
  +        final SyntaxTreeNode item = (SyntaxTreeNode) elementAt(j);
  +        if (item instanceof Variable) {
  +            item.translate(classGen, methodGen);
  +            removeElement(item);     // avoid translating it twice
  +            /* When removing an element we do not increment j
  +             * but the removal will reduce the value of elementCount()
  +             * so this loop WILL end. The next iteration will process
  +             * elementAt(j), but with the old element removed
  +             * we are actually processing the next element.
  +             */
            }
  +        else
  +            j++;
        }
   
        // Compile code to emit namespace attributes
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to