Hi,

before I prepare a self-contained test case, perhaps this description already rings a bell:

I'm getting with the latest 6.2.2 this NPE:

java.lang.NullPointerException
       at org.basex.query.up.primitives.UpdatePrimitive.addNode(UpdatePrimitive.java:193)
       at org.basex.query.up.primitives.UpdatePrimitive.addNode(UpdatePrimitive.java:214)
       at org.basex.query.up.primitives.UpdatePrimitive.buildDB(UpdatePrimitive.java:133)
       at org.basex.query.up.primitives.NodeCopy.prepare(NodeCopy.java:47)
       at org.basex.query.up.Primitives.check(Primitives.java:67)
       at org.basex.query.up.DBPrimitives.check(DBPrimitives.java:45)
       at org.basex.query.up.Updates.apply(Updates.java:102)
       at org.basex.query.QueryContext.iter(QueryContext.java:299)
       at org.basex.api.xqj.BXQDynamicContext.execute(BXQDynamicContext.java:266)
       at org.basex.api.xqj.BXQPreparedExpression.executeQuery(BXQPreparedExpression.java:55)

This happens when I pass an actual DOM node to bindNode as argument 2.
The error does not occur, and the query runs successfully, when I instead pass the node's ownerDocument. The node is the root of its document.

Actual code:

Works:
   xqp.bindNode(new QName("entry"), elem.getOwnerDocument(), null);

Fails:
   xqp.bindNode(new QName("entry"), elem, null);

Here, 'elem' is the root node of a document created via parseXml from a string. It uses the JDK's DOM implementation.

I note that in the second bug we're discussing, BaseX also shows different behavior for nodes that are the root nodes of their respective documents when passed to bindNode. Which makes me wonder what the correct behavior is. It seems to me that passing a document or its root node to bindNode should result in the same behavior; correct?

Thanks.

 - Godmar