XQuery-Java-Binding: Nullpointer "nsMap" is null (on returning a w3c.dom.Node)
Monday, 28 August 2023 · 5 messages
AN
Andreas Hengsbach | nexoma28 Aug 2023 12:27 #
Hi all,
in a Java module I create a "org.w3c.dom.Node" (with
java.xml.parsers.DocumentBuilder) and return it to XQuery/BaseX.
Since 10.7 I get this exception:
# schnipp
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.basex.util.hash.TokenMap.put(byte[], byte[])" because "nsMap" is null
at org.basex.query.value.node.FElem.build(FElem.java:99)
at org.basex.query.value.type.NodeType$3.cast(NodeType.java:60)
at org.basex.query.value.type.NodeType$3.cast(NodeType.java:55)
at org.basex.query.func.java.JavaCall.toValue(JavaCall.java:262)
at org.basex.query.func.java.DynJavaFunc.eval(DynJavaFunc.java:90)
at org.basex.query.func.java.JavaCall.value(JavaCall.java:81)
at org.basex.query.expr.List.value(List.java:230)
at org.basex.query.expr.gflwor.GFLWOR.value(GFLWOR.java:92)
at org.basex.query.expr.gflwor.Let$LetEval.next(Let.java:146)
at org.basex.query.expr.gflwor.GFLWOR.value(GFLWOR.java:92)
at org.basex.query.expr.Try.value(Try.java:93)
at org.basex.query.expr.List.value(List.java:226)
at org.basex.query.expr.gflwor.GFLWOR.value(GFLWOR.java:92)
at org.basex.query.expr.List.value(List.java:230)
at org.basex.query.expr.If.value(If.java:158)
at org.basex.query.expr.List.value(List.java:230)
at org.basex.query.expr.Try.value(Try.java:93)
at org.basex.query.expr.gflwor.GFLWOR.value(GFLWOR.java:92)
at org.basex.query.expr.If.value(If.java:158)
at org.basex.query.expr.List.value(List.java:226)
at org.basex.query.expr.Try.value(Try.java:93)
at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:46)
at org.basex.query.scope.MainModule.iter(MainModule.java:48)
at org.basex.query.QueryContext.lambda$iter$4(QueryContext.java:357)
at org.basex.query.QueryContext.run(QueryContext.java:766)
at org.basex.query.QueryContext.iter(QueryContext.java:357)
at org.basex.query.QueryProcessor.iter(QueryProcessor.java:95)
# schnapp
Do I have to create the Node differently now, or is this a bug?
nsMap. a map of namespace I guess. In my case the w3c.dom.Node has no namespace.
Thanks a lot
Andreas
CG
Christian Grün28 Aug 2023 12:30 #
Hi Andreas,
Quoted text · Andreas Hengsbach | nexoma · 3 lines
in a Java module I create a "org.w3c.dom.Node" (with > java.xml.parsers.DocumentBuilder) and return it to XQuery/BaseX. >
Could you please provide us with a minimized Java example class that allows us to reproduce the problem?
Thanks in advance,
Christian
AN
Andreas Hengsbach | nexoma28 Aug 2023 13:12 #
Hi Christian,
this one already leads into the error.
# schnipp
public class DomNodeBaseXTest {
public DomNodeBaseXTest() {}
public Node myTestCase() throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("root");
Element subElement = doc.createElement("leaf");
subElement.setTextContent("myText");
rootElement.appendChild(subElement);
return rootElement;
}
}
# schnapp
Thanks a lot
Andreas
CG
Christian Grün28 Aug 2023 13:30 #
Thanks; a fix is available [1,2].
[1] https://files.basex.org/releases/latest/
[2]
https://github.com/BaseXdb/basex/commit/48a17c0cc1664e5fa6d6cf07eb437cd35296c485
Quoted text · Andreas Hengsbach | nexoma · 69 lines
On Mon, Aug 28, 2023 at 1:12 PM Andreas Hengsbach | nexoma < andreas.hengsbach at nexoma.de> wrote: > Hi Christian, > > > > this one already leads into the error. > > > > # schnipp > > public class DomNodeBaseXTest { > > > > public DomNodeBaseXTest() {} > > > > public Node myTestCase() throws > ParserConfigurationException { > > DocumentBuilderFactory docFactory = > DocumentBuilderFactory.newInstance(); > > > > DocumentBuilder docBuilder = > docFactory.newDocumentBuilder(); > > Document doc = docBuilder.newDocument(); > > > > Element rootElement = > doc.createElement("root"); > > > > Element subElement = > doc.createElement("leaf"); > > subElement.setTextContent("myText"); > > > > rootElement.appendChild(subElement); > > > > return rootElement; > > } > > > > } > > # schnapp > > > > Thanks a lot > > Andreas > > >
AN
Andreas Hengsbach | nexoma28 Aug 2023 14:03 #
Hi Christian,
wow, that was lightning fast. 😊
It works like clockwork.
Thanks
Andreas
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery