-
-
Notifications
You must be signed in to change notification settings - Fork 190
[bugfix] fn:transform: Conversion and treeIndex problems #5680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop-6.x.x
Are you sure you want to change the base?
Conversation
@wolfgangmm please can you check? |
It appears there is another (different) problem with the way |
I have added two more commits.
The second commit fixes another bug in the handling of |
There was another problem with the the 'path' returned by I think that what |
return sibling; | ||
} | ||
|
||
static XdmNode xdmNodeAtIndex(final XdmNode xdmNode, final List<Integer> index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method not be adapted? This loops over children()
, are these not including attributes?
Thanks @nverwer again for your contribution. We will pull it in once we have at least one positive and one negative test for it. |
Or maybe it is easier to test in XQuery? |
@nverwer thank you for the time you spend on this. We would like to include this PR in a patch release of exist. Could you rebase the PR please so, we can start with a cleaner commit history? I will try to help you with adding a test case. Did you succeed in the meantime in wiggling things down? Could you share the |
What should I rebase this on? EDIT: I see, it is develop-6.x.x. About a test case: We had the problem several months ago in a very large application. I could not make a concise test case back then, and it would be even more difficult now. Designing a test case requires a thorough understanding of the internal representations of XML in eXist-db, which I do not have. I apologize for not coming up with a useful test. I am aware that eXist can only advance by the efforts of the community around it. |
After spending some time trying to rebase, it all seems to be terribly messed up, even resulting in automatically closing this PR. There are close to a 100 files with merge conflicts, most of which are totally unrelated to this PR. I have no idea why this went horribly wrong. I will give it one more try before giving up. |
Fixes NPE in fn:transform. Allows arrays and maps to be passed as parameters to an XSLT. Show location when an XSLT throws an exception.
I tried to apply the changes to develop-6.x.x and will reopen this PR. |
@nverwer thank you, gave me quite a scare there for a minute |
|
Description
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'.
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, but I will keep trying.