You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Norman Walsh <nd...@nwalsh.com> on 2001/02/20 15:50:58 UTC

Bug in ElementImpl.java

In Xalan2's ElementImpl.java, I believe there is a bug in
getChildAttribute(). The code path that begins with getValue(String)
on an AttList passes through

  public Node getNamedItem(String name)
  {
    return getChildAttribute(getIndex(name));
  }

and if the attribute 'name' doesn't occur in the AttList, the
result of getIndex(name) is -1. But in that case, getChildAttribute():

  public AttrImpl getChildAttribute(int i)
          throws ArrayIndexOutOfBoundsException, NullPointerException
  {

    synchronized (m_doc)
    {
      if (null != m_firstAttr)
      {
        Child next = m_firstAttr;

        for (int k = 0; k < i; k++)
        {
          if (null == next)
            return null;

          next = next.m_next;
        }

        return (AttrImpl) next;
      }
      else
        return null;
    }
  }

returns "next", which is m_firstAttr if the AttList is not empty, when
it should return null.  Adding

    if (i < 0)
      return null;

before "synchronized (m_doc)" is a workaround. It may also be a fix,
but I don't know the internals of Xalan2 well enough to understand
if passing -1 to this function is what should be avoided.

                                        Be seeing you,
                                          norm

-- 
Norman.Walsh@East.Sun.COM    | The years teach us much which the days
XML Standards Engineer       | never knew.--Emerson
Technology Development Group | 
Sun Microsystems, Inc.       |