Commons JXPath
  1. Commons JXPath
  2. JXPATH-135

Potential infinite loop in NamespaceResolver.getPrefix()

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: None
    • Labels:
      None

      Description

      There appears to be an inifinite loop in org.apache.commons.jxpath.ri.NamespaceResolver.getPrefix(). While I haven't yet been able to create a minimal test app that reproduces the problem, the bug seems fairly self-evident from the code.

      protected static String getPrefix(NodePointer pointer, String namespaceURI) {
              NodePointer currentPointer = pointer;
              while (currentPointer != null) {
                  NodeIterator ni = currentPointer.namespaceIterator();
                  for (int position = 1; ni != null && ni.setPosition(position); position++) {
                      NodePointer nsPointer = ni.getNodePointer();
                      String uri = nsPointer.getNamespaceURI();
                      if (uri.equals(namespaceURI)) {
                          String prefix = nsPointer.getName().getName();
                          if (!"".equals(prefix)) {
                              return prefix;
                          }
                      }
                  }
                  currentPointer = pointer.getParent();
              }
              return null;
          }
      

      The problem line is the last line in the loop: 'currentPointer = pointer.getParent();'. As the 'pointer' variable never changes, the value of 'currentPointer' never changes between loop iterations after the second iteration. Consequently if the namespace prefix is not found in the first two iterations, an infinite loop occurs. The problem seems to be resolved by changing that line to 'currentPointer = currentPointer.getParent();'.

        Issue Links

          Activity

          Hide
          Matt Benson added a comment -

          Agreed that the bug is self-evident on a code review. Thanks for the report.

          Committed revision 918623.

          Show
          Matt Benson added a comment - Agreed that the bug is self-evident on a code review. Thanks for the report. Committed revision 918623.

            People

            • Assignee:
              Unassigned
              Reporter:
              Dave Bryant
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development