You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2003/08/07 14:43:33 UTC

DO NOT REPLY [Bug 22212] New: - removeElement, Coding Error, does not delete properly

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

removeElement, Coding Error, does not delete properly

           Summary: removeElement, Coding Error, does not delete properly
           Product: XalanJ2
           Version: 2.5
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: org.apache.xpath
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: brandt@pdtec.de


NodeSet filled with three Elements e1,e2,e3, when deleting in the same order
only removes the first two elements.

Erronous Code with proposed fix below

public boolean removeElement(Node s)
  {
    if (!m_mutable)
      throw new RuntimeException(XSLMessages.createXPATHMessage
(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not 
mutable!");

    if (null == m_map)
      return false;

    for (int i = 0; i < m_firstFree; i++)
    {
      Node node = m_map[i];

      if ((null != node) && node.equals(s))
      {
        if (i > m_firstFree)  <<<<<<< BUG  can never be true,
                              <<<<<<< must be "<" instead of ">"
          System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i);
        else
          m_map[i] = null;

        m_firstFree--;

        return true;
      }
    }

    return false;
  }