In JAXP 1.0.1, the item(index) method sometimes fails to return the last item

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 1.1.1
    • Affects Version/s: 1.0.1
    • Component/s: xml
    • 1.1.1
    • generic
    • generic
    • Verified



      Name: boT120536 Date: 01/29/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      In JAXP 1.0.1, the item(index) method sometimes fails to return the last item
      of a NodeList.

      I came across the problem when I had a list with just 1 node: item(0) returns
      that node and item(1) returns null (as expected), but subsequent calls to
      item(0) always return null instead of the node.

      I think there is a general problem, as follows:-

          NodeList list = parentElem.getElementsByTagName("whatever");
          int n = list.getLength();
          Element elem;
          elem = (Element) list.item(n - 1); // works OK (returns last item)
          elem = (Element) list.item(n); // works OK (returns null)
          elem = (Element) list.item(n - 1); // fails - returns null instead of last
      item

      (I believe the problem is in the TagList class of ParentNode.java, in that
      lastIndex is not incremented when lastWalker.getNextElement returns null.
      Next time, the walker is not in the expected position and lastWalker.getCurrent
      is mistakenly used).
      (Review ID: 115317)
      ======================================================================

            Assignee:
            Edwin Goei (Inactive)
            Reporter:
            Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: