Adrian Nistor created PDFBOX-1654:
-------------------------------------
Summary: Wasted work in XMLUtil.getNodeValue
Key: PDFBOX-1654
URL: https://issues.apache.org/jira/browse/PDFBOX-1654
Project: PDFBox
Issue Type: Bug
Affects Versions: 1.8.2
Environment: any
Reporter: Adrian Nistor
Attachments: patch.diff, patchShort.diff
The problem appears in version 1.8.2 and in revision 1497941. I
attached a two-line patch (patch.diff) that fixes it.
In method "XMLUtil.getNodeValue", the loop over "children" keeps
overriding "retval" with "next.getNodeValue()". Therefore, only the
last written value is visible out of the loop and all the other writes
and iterations are not necessary. The patch iterates from the end of
"children" and breaks the first time when "retval" is set.
The above fix (in patch.diff) is certainly correct (it's easy to see
through code inspection), but I think we can have an even shorter
patch (one line, in patchShort.diff): just break as soon as "retval"
is set, without reversion the loop order. patchShort.diff is correct
only if there can be only one "Text" child, or if it doesn't matter
which "Text" child is returned (the last, like in the original code,
or the first, like in patchShort.diff).
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira