NullPointerException parsing trivial query using XQJ (CLI works)

Monday, 27 January 2020 · 4 messages · last reply 28 Jan 2020
AS
Andreas Sewe27 Jan 2020 17:42 #
Hi, I get a weird NPE/parse error when interfacing with BaseX 9.3.1 via XQJ and even occurs for the following minimal query:
  <html>{.}</html>
In other words, I just want to interpolate the context item. The gist of the XQJ calls is the following:
Quoted text · 4 lines
> XQPreparedExpression expression = connection.prepareExpression("<html>{.}</html>"); > expression.bindDocument(XQConstants.CONTEXT_ITEM, "<context/>", null, null); > XQResultSequence results = expression.executeQuery(); > results.writeSequence(System.out, null);
This results in the following message
Quoted text · 1 line
> XQJQS001 - Invalid XQuery syntax, syntax does not pass static validation.
and a long and unfortunately obfuscated stack trace:
Quoted text · 67 lines
> java.lang.NullPointerException > at net.xqj.basex.bin.bz.a(Unknown Source) > at net.xqj.basex.bin.bv.c(Unknown Source) > at net.xqj.basex.bin.bC.bE(Unknown Source) > at net.xqj.basex.bin.bC.by(Unknown Source) > at net.xqj.basex.bin.bC.bu(Unknown Source) > at net.xqj.basex.bin.bC.bj(Unknown Source) > at net.xqj.basex.bin.bC.bi(Unknown Source) > at net.xqj.basex.bin.bC.bh(Unknown Source) > at net.xqj.basex.bin.bC.aY(Unknown Source) > at net.xqj.basex.bin.bC.aX(Unknown Source) > at net.xqj.basex.bin.bC.aW(Unknown Source) > at net.xqj.basex.bin.bC.aV(Unknown Source) > at net.xqj.basex.bin.bC.aU(Unknown Source) > at net.xqj.basex.bin.bC.aT(Unknown Source) > at net.xqj.basex.bin.bC.aS(Unknown Source) > at net.xqj.basex.bin.bC.aR(Unknown Source) > at net.xqj.basex.bin.bC.aQ(Unknown Source) > at net.xqj.basex.bin.bC.aP(Unknown Source) > at net.xqj.basex.bin.bC.aO(Unknown Source) > at net.xqj.basex.bin.bC.aN(Unknown Source) > at net.xqj.basex.bin.bC.aM(Unknown Source) > at net.xqj.basex.bin.bC.aL(Unknown Source) > at net.xqj.basex.bin.bC.aK(Unknown Source) > at net.xqj.basex.bin.bC.R(Unknown Source) > at net.xqj.basex.bin.bC.Q(Unknown Source) > at net.xqj.basex.bin.bC.N(Unknown Source) > at net.xqj.basex.bin.bC.bS(Unknown Source) > at net.xqj.basex.bin.bC.bR(Unknown Source) > at net.xqj.basex.bin.bC.bM(Unknown Source) > at net.xqj.basex.bin.bC.bL(Unknown Source) > at net.xqj.basex.bin.bC.bK(Unknown Source) > at net.xqj.basex.bin.bC.by(Unknown Source) > at net.xqj.basex.bin.bC.bu(Unknown Source) > at net.xqj.basex.bin.bC.bj(Unknown Source) > at net.xqj.basex.bin.bC.bi(Unknown Source) > at net.xqj.basex.bin.bC.bh(Unknown Source) > at net.xqj.basex.bin.bC.aY(Unknown Source) > at net.xqj.basex.bin.bC.aX(Unknown Source) > at net.xqj.basex.bin.bC.aW(Unknown Source) > at net.xqj.basex.bin.bC.aV(Unknown Source) > at net.xqj.basex.bin.bC.aU(Unknown Source) > at net.xqj.basex.bin.bC.aT(Unknown Source) > at net.xqj.basex.bin.bC.aS(Unknown Source) > at net.xqj.basex.bin.bC.aR(Unknown Source) > at net.xqj.basex.bin.bC.aQ(Unknown Source) > at net.xqj.basex.bin.bC.aP(Unknown Source) > at net.xqj.basex.bin.bC.aO(Unknown Source) > at net.xqj.basex.bin.bC.aN(Unknown Source) > at net.xqj.basex.bin.bC.aM(Unknown Source) > at net.xqj.basex.bin.bC.aL(Unknown Source) > at net.xqj.basex.bin.bC.aK(Unknown Source) > at net.xqj.basex.bin.bC.R(Unknown Source) > at net.xqj.basex.bin.bC.Q(Unknown Source) > at net.xqj.basex.bin.bC.P(Unknown Source) > at net.xqj.basex.bin.bC.d(Unknown Source) > at net.xqj.basex.bin.bC.b(Unknown Source) > at net.xqj.basex.bin.bC.a(Unknown Source) > at net.xqj.basex.bin.bC.a(Unknown Source) > at net.xqj.basex.bin.bJ.<init>(Unknown Source) > at net.xqj.basex.bin.bd.a(Unknown Source) > at net.xqj.basex.bin.H.<init>(Unknown Source) > at net.xqj.basex.bin.H.a(Unknown Source) > at net.xqj.basex.bin.u.a(Unknown Source) > at net.xqj.basex.bin.u.a(Unknown Source) > at net.xqj.basex.bin.w.prepareExpression(Unknown Source) > at net.xqj.basex.bin.w.prepareExpression(Unknown Source)
Executing the same query using "bin/basex -i context.xml query.xq" outputs the expected result:
Quoted text · 3 lines
> <html> > <context/> > </html>
I have a minimal (Maven-based) test project, in case you want to reproduce the bug. I can also file the issue on GitHub, if that's the preferred method, but if I read <https://github.com/BaseXdb/basex/issues/new> correctly, then I should post here first. Best wishes, Andreas
CG
Christian Grün28 Jan 2020 10:41 #
Hi Andreas, The XQJ driver comes with its own XQuery parser, which differs from the BaseX query parser. It has been a closed-source development from Charles Foster [1]; you may need to directly contact him to see if there is a chance to get this fixed. As there haven’t been any considerable updates for a long time now, and as more recent features of XQuery are not supported by XQJ, we usually recommend users to work with our own APIs [2]. If you need a quick workaround, I noticed you can rewrite your query to:
  <html{ (.) }</html>
Quoted text · Andreas Sewe · 1 line
> if I read <https://github.com/BaseXdb/basex/issues/new> correctly, then I should post here first.
Exactly; thanks. Christian [1] http://xqj.net [2] http://docs.basex.org/wiki/Developing
Quoted text · Andreas Sewe · 110 lines
On Mon, Jan 27, 2020 at 5:42 PM Andreas Sewe <sewe at st.informatik.tu-darmstadt.de> wrote: > > Hi, > > I get a weird NPE/parse error when interfacing with BaseX 9.3.1 via XQJ > and even occurs for the following minimal query: > > <html>{.}</html> > > In other words, I just want to interpolate the context item. > > The gist of the XQJ calls is the following: > > > XQPreparedExpression expression = connection.prepareExpression("<html>{.}</html>"); > > expression.bindDocument(XQConstants.CONTEXT_ITEM, "<context/>", null, null); > > XQResultSequence results = expression.executeQuery(); > > results.writeSequence(System.out, null); > > This results in the following message > > > XQJQS001 - Invalid XQuery syntax, syntax does not pass static validation. > > and a long and unfortunately obfuscated stack trace: > > > java.lang.NullPointerException > > at net.xqj.basex.bin.bz.a(Unknown Source) > > at net.xqj.basex.bin.bv.c(Unknown Source) > > at net.xqj.basex.bin.bC.bE(Unknown Source) > > at net.xqj.basex.bin.bC.by(Unknown Source) > > at net.xqj.basex.bin.bC.bu(Unknown Source) > > at net.xqj.basex.bin.bC.bj(Unknown Source) > > at net.xqj.basex.bin.bC.bi(Unknown Source) > > at net.xqj.basex.bin.bC.bh(Unknown Source) > > at net.xqj.basex.bin.bC.aY(Unknown Source) > > at net.xqj.basex.bin.bC.aX(Unknown Source) > > at net.xqj.basex.bin.bC.aW(Unknown Source) > > at net.xqj.basex.bin.bC.aV(Unknown Source) > > at net.xqj.basex.bin.bC.aU(Unknown Source) > > at net.xqj.basex.bin.bC.aT(Unknown Source) > > at net.xqj.basex.bin.bC.aS(Unknown Source) > > at net.xqj.basex.bin.bC.aR(Unknown Source) > > at net.xqj.basex.bin.bC.aQ(Unknown Source) > > at net.xqj.basex.bin.bC.aP(Unknown Source) > > at net.xqj.basex.bin.bC.aO(Unknown Source) > > at net.xqj.basex.bin.bC.aN(Unknown Source) > > at net.xqj.basex.bin.bC.aM(Unknown Source) > > at net.xqj.basex.bin.bC.aL(Unknown Source) > > at net.xqj.basex.bin.bC.aK(Unknown Source) > > at net.xqj.basex.bin.bC.R(Unknown Source) > > at net.xqj.basex.bin.bC.Q(Unknown Source) > > at net.xqj.basex.bin.bC.N(Unknown Source) > > at net.xqj.basex.bin.bC.bS(Unknown Source) > > at net.xqj.basex.bin.bC.bR(Unknown Source) > > at net.xqj.basex.bin.bC.bM(Unknown Source) > > at net.xqj.basex.bin.bC.bL(Unknown Source) > > at net.xqj.basex.bin.bC.bK(Unknown Source) > > at net.xqj.basex.bin.bC.by(Unknown Source) > > at net.xqj.basex.bin.bC.bu(Unknown Source) > > at net.xqj.basex.bin.bC.bj(Unknown Source) > > at net.xqj.basex.bin.bC.bi(Unknown Source) > > at net.xqj.basex.bin.bC.bh(Unknown Source) > > at net.xqj.basex.bin.bC.aY(Unknown Source) > > at net.xqj.basex.bin.bC.aX(Unknown Source) > > at net.xqj.basex.bin.bC.aW(Unknown Source) > > at net.xqj.basex.bin.bC.aV(Unknown Source) > > at net.xqj.basex.bin.bC.aU(Unknown Source) > > at net.xqj.basex.bin.bC.aT(Unknown Source) > > at net.xqj.basex.bin.bC.aS(Unknown Source) > > at net.xqj.basex.bin.bC.aR(Unknown Source) > > at net.xqj.basex.bin.bC.aQ(Unknown Source) > > at net.xqj.basex.bin.bC.aP(Unknown Source) > > at net.xqj.basex.bin.bC.aO(Unknown Source) > > at net.xqj.basex.bin.bC.aN(Unknown Source) > > at net.xqj.basex.bin.bC.aM(Unknown Source) > > at net.xqj.basex.bin.bC.aL(Unknown Source) > > at net.xqj.basex.bin.bC.aK(Unknown Source) > > at net.xqj.basex.bin.bC.R(Unknown Source) > > at net.xqj.basex.bin.bC.Q(Unknown Source) > > at net.xqj.basex.bin.bC.P(Unknown Source) > > at net.xqj.basex.bin.bC.d(Unknown Source) > > at net.xqj.basex.bin.bC.b(Unknown Source) > > at net.xqj.basex.bin.bC.a(Unknown Source) > > at net.xqj.basex.bin.bC.a(Unknown Source) > > at net.xqj.basex.bin.bJ.<init>(Unknown Source) > > at net.xqj.basex.bin.bd.a(Unknown Source) > > at net.xqj.basex.bin.H.<init>(Unknown Source) > > at net.xqj.basex.bin.H.a(Unknown Source) > > at net.xqj.basex.bin.u.a(Unknown Source) > > at net.xqj.basex.bin.u.a(Unknown Source) > > at net.xqj.basex.bin.w.prepareExpression(Unknown Source) > > at net.xqj.basex.bin.w.prepareExpression(Unknown Source) > > Executing the same query using "bin/basex -i context.xml query.xq" > outputs the expected result: > > > <html> > > <context/> > > </html> > > I have a minimal (Maven-based) test project, in case you want to > reproduce the bug. I can also file the issue on GitHub, if that's the > preferred method, but if I read > <https://github.com/BaseXdb/basex/issues/new> correctly, then I should > post here first. > > Best wishes, > > Andreas >
AS
Andreas Sewe28 Jan 2020 11:46 #
Hi Christian,
Quoted text · Christian Grün · 2 lines
> The XQJ driver comes with its own XQuery parser, which differs from > the BaseX query parser.
Interesting. That's not what I would have been expecting. May I inquire why this is done like this?
Quoted text · Christian Grün · 3 lines
> It has been a closed-source development from > Charles Foster [1]; you may need to directly contact him to see if > there is a chance to get this fixed.
OK, I will try, but I am afraid that is not the only parser issue I am encountering, merely the one with the simplest steps to reproduce, so even if Charles is responsive, this may mean embarking on a longer journey.
Quoted text · Christian Grün · 3 lines
> As there haven’t been any considerable updates for a long time now, > and as more recent features of XQuery are not supported by XQJ, we > usually recommend users to work with our own APIs [2].
Yes, that's essentially the same response I got on saxon-help (use their S9API). Unfortunately, for my use case that is less than ideal: I am developing a plug-in for Maven (unsurprisingly named xquery-maven-plugin) that does for XQuery what the xml-maven-plugin does for XSLT [1]: offer a goal to query and transform some inputs w.r.t. to a stylesheet/query. Thus, my plug-in requires a common interface to the XQuery engines. XQJ seemed like the natural conterpart of javax.xml.transform used by the xml-maven-plugin, but I guess I really have to to write my own wrapper around Saxon's S9API and BaseX's API, if only because the XQJ integration seems to be among the least tested and most buggy parts of the XQuery engines I have tried so far. Best wishes, Andreas Sewe [1] <https://www.mojohaus.org/xml-maven-plugin/transform-mojo.html>
CG
Christian Grün28 Jan 2020 11:58 #
Quoted text · Andreas Sewe · 2 lines
> Interesting. That's not what I would have been expecting. May I inquire > why this is done like this?
Once again, a solution chosen by the developer… I assume this is because the same XQJ base driver was used for a range of XQuery processors (eXist-db, Sedna, Marklogic).
Quoted text · Andreas Sewe · 6 lines
> Thus, my plug-in requires a common interface to the XQuery engines. XQJ > seemed like the natural conterpart of javax.xml.transform used by the > xml-maven-plugin, but I guess I really have to to write my own wrapper > around Saxon's S9API and BaseX's API, if only because the XQJ > integration seems to be among the least tested and most buggy parts of > the XQuery engines I have tried so far.
I guess so. A clean abstraction for the Java and XQuery world often be helpful, but XQJ was discontinued at a rather early stage. One open issue from the very beginning was that it assumed the underlying processor to behave in certain ways, which did not reflect the reality of existing processors. And around 10 years ago, we were maintaining our own XQJ implementation, but it was too much effort to keep it alive (too few developers were using it).

⚡Generated with XQuery