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

          Dave Bryant created issue -
          Matt Benson made changes -
          Field Original Value New Value
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Matt Benson made changes -
          Link This issue is duplicated by JXPATH-140 [ JXPATH-140 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development