Hello folk.

Since version xalan 2-4-0 I'm getting a NullPointerException:

Exception in thread "main" java.lang.NullPointerException
        at org.apache.xml.dtm.ref.DTMNodeList.item(DTMNodeList.java:164)
        at ApplyXPath2.doMain(ApplyXPath2.java:134)
        at ApplyXPath2.main(ApplyXPath2.java:164)

Here is what I'm doing:
           NodeList nl = XPathAPI.selectNodeList(doc, xpath);
            int index = 0;
            for (; nl.item(index) != null; index++);

With slectNodeIterator(..) i've no problems.

I think I've found the workaround: I just added the follow if statement in
the DTMNodeList.item() (just like in the DTMNodeIterator.nextNode()
function)

    public Node item(int index)
    {
      if(dtm_iter!=null)
      {
        int handle=dtm_iter.item(index);

/* Added if Statement */
        if (handle==-1)
            return null;
/* Added if Statement */

        return dtm_iter.getDTM(handle).getNode(handle);
      }
      else
      {
        int handle=m_firstChild;
        while(--index>=0 && handle!=DTM.NULL)
          handle=m_parentDTM.getNextSibling(handle);
        return m_parentDTM.getNode(handle);
      }
    }

Here the original  DTMNodeIterator.nextNode() function with if statement

  public Node nextNode() throws DOMException
    {
      if(!valid)
        throw new DTMDOMException(DOMException.INVALID_STATE_ERR);

      int handle=dtm_iter.nextNode();
      if (handle==-1)
        return null;
      return dtm_iter.getDTM(handle).getNode(handle);
    }

Question: was it really an error, or am I doing something wrong?
Thank in advance.

David Ostrovsky



Reply via email to