commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dave Bryant (JIRA)" <j...@apache.org>
Subject [jira] Created: (JXPATH-135) Potential infinite loop in NamespaceResolver.getPrefix()
Date Tue, 11 Aug 2009 07:55:15 GMT
Potential infinite loop in NamespaceResolver.getPrefix()
--------------------------------------------------------

                 Key: JXPATH-135
                 URL: https://issues.apache.org/jira/browse/JXPATH-135
             Project: Commons JXPath
          Issue Type: Bug
    Affects Versions: 1.3
            Reporter: Dave Bryant


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.

{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;
    }
{code}

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();'.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message