[bugfix] fn:transform: Conversion and treeIndex problems #5882
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is a retry for #5680 which was botched after I changed my develop-6.x.x branch.
The
fn:transform
function sometimes producedNullPointerException
s. This happened for documents containing nodes of typeorg.exist.dom.memtree.ElementImpl
and other subtypes oforg.exist.dom.memtree.NodeImpl
.The function
org.exist.xquery.functions.fn.transform.Convert.ToSaxon.ofNode(Node)
usesorg.exist.xquery.functions.fn.transform.TreeUtils.treeIndex(Node)
to get a 'path' (as a list of indexes) of theNode
in its containing document. This 'path' is used to find the node in a newly built document that is suitable for use by Saxon.Using the 'path' that the
treeIndex
function produces assumes that it starts at the document node.However, some nodes do not have a containing document. Specifically, in
org.exist.dom.memtree.NodeImpl.getParentNode()
:In this case, the 'path' returned by
treeIndex
does not contain the index (0) for the root node, andorg.exist.xquery.functions.fn.transform.TreeUtils.xdmNodeAtIndex(XdmNode, List<Integer>)
will returnnull
when a node is expected.The proposed fix tests for this case. Going up the ancestor chain, when a node that is not a document node and that does not have a parent is found, the index 0 for this root element is inserted in the 'path'.
The PR also adds support for using maps and arrays as parameters in a XSLT transformation.
Testing
The
NullPointerException
happened in a rather complicated XQuery with documents composed from several sources.I have not yet been able to make a simple test case.