[
https://issues.apache.org/jira/browse/JXPATH-135?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Matt Benson resolved JXPATH-135.
--------------------------------
Resolution: Fixed
Agreed that the bug is self-evident on a code review. :) Thanks for the
report.
Committed revision 918623.
> 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.