Exist: Null Pointer exception on inspect:inspect-module()

Created on 1 Feb 2017  路  10Comments  路  Source: eXist-db/exist

Following simple query causes a NullPointerException in 3.0RC1 under Windows.

Filename : thisquery.xql

xquery version "3.0";

import module namespace inspect = "http://exist-db.org/xquery/inspection";

let $data := inspect:inspect-module(xs:anyURI("xmldb:exist:///db/apps/JonathanTest/thisquery.xql"))
return
  $data

ie: it is inspecting itself.

java.lang.NullPointerException
    at org.exist.xquery.XQueryContext.compileOrBorrowModule(XQueryContext.java:2835) ~[exist.jar:?]
    at org.exist.xquery.XQueryContext.importModule(XQueryContext.java:2748) ~[exist.jar:?]
    at org.exist.xquery.functions.inspect.InspectModule.eval(InspectModule.java:66) ~[exist.jar:?]
    at org.exist.xquery.BasicFunction.eval(BasicFunction.java:70) ~[exist.jar:?]
    at org.exist.xquery.InternalFunctionCall.eval(InternalFunctionCall.java:56) ~[exist.jar:?]
    at org.exist.xquery.LetExpr.eval(LetExpr.java:142) ~[exist.jar:?]
    at org.exist.xquery.BindingExpression.eval(BindingExpression.java:165) ~[exist.jar:?]
    at org.exist.xquery.AbstractExpression.eval(AbstractExpression.java:71) ~[exist.jar:?]
    at org.exist.xquery.PathExpr.eval(PathExpr.java:267) ~[exist.jar:?]
    at org.exist.xquery.AbstractExpression.eval(AbstractExpression.java:71) ~[exist.jar:?]
    at org.exist.xquery.XQuery.execute(XQuery.java:280) ~[exist.jar:?]
    at org.exist.xquery.XQuery.execute(XQuery.java:200) ~[exist.jar:?]
    at org.exist.http.servlets.XQueryServlet.process(XQueryServlet.java:492) [exist-optional.jar:?]
    at org.exist.http.servlets.XQueryServlet.doPost(XQueryServlet.java:198) [exist-optional.jar:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:755) [servlet-api-3.0.jar:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [servlet-api-3.0.jar:?]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:575) [jetty-security-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:229) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:103) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.exist.http.urlrewrite.Forward.doRewrite(Forward.java:50) [exist-optional.jar:?]
    at org.exist.http.urlrewrite.XQueryURLRewrite.doRewrite(XQueryURLRewrite.java:557) [exist-optional.jar:?]
    at org.exist.http.urlrewrite.XQueryURLRewrite.service(XQueryURLRewrite.java:357) [exist-optional.jar:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [servlet-api-3.0.jar:?]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at de.betterform.agent.web.filter.XFormsFilter.doFilter(XFormsFilter.java:171) [betterform-exist-5.1-SNAPSHOT-20150603.jar:?]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1476) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533) [jetty-security-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429) [jetty-servlet-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.Server.handle(Server.java:370) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865) [jetty-http-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240) [jetty-http-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) [jetty-server-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696) [jetty-io-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53) [jetty-io-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-8.1.17.v20150415.jar:8.1.17.v20150415]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-8.1.17.v20150415.jar:8.1.17.v20150415]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
bug

All 10 comments

Confirmed with current develop branch.

Confirmed also with version 2017-02-01 Git Hash c1b5b79.

The stack trace is the same except that the crash point is now at line 2822 instead of 2835.

The issue you have is because you are trying to pass a main module to inspect:inspect-module.

inspect:inspect-module only works with library modules, although that was not clear from the documentation. I just fixed the NPE and updated the documentation here - https://github.com/eXist-db/exist/pull/1372

Calling inspect:inspect-module on a main module now returns an empty sequence.

If inspect-module only works on library modules, why should it return an empty sequence. I would have though that inspect-module ought to return a something from a library module and nothing otherwise.

There are too many "modules" in the names.
I call XQueries with a module statement a "module" and those without just queries.

@JonathanRowell I am not sure if I understand what you suggest? the Java NPE is gone now, that is good. In essence there are two options for returning: an error or a empty sequence. I am not too fond of raising errors (try-catch required), so the empty sequence is a good alternative. For me, this is a good change.

@JonathanRowell Re: what to call XQuery files, you might find these discussions useful:

@dizzz I've read Adam's comment now six times. The last sentence should read "Calling inspect:inspect-module on aN NON- library module now returns an empty sequence."

Yes it is the correct change, since an exception should only be raised if the "thing" being inspected is not well formed.

@JonathanRowell I chose to return an empty sequence if you try against a main module, because inspect:inspect-module would previously also return an empty sequence if you tried against a URI that did not exist. So keeping the same orthogonality of errors seemed sensible to me.

I note also that in XQuery terms an empty sequence is the equivalent of "nothing".

@joewiz I don't want to go down that road! But one can get tongue tied now and again.

@JonathanRowell You are right, there was a mistake in my comment, I have now updated it.

Was this page helpful?
0 / 5 - 0 ratings