Project

Profile

Help

Bug #4684

closed

NullPointerException compiling a stylesheet using eXist-DB transform() function

Added by Michael Kay over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2020-08-14
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 9.9, trunk
Fix Committed on Branch:
10, 9.9, trunk
Fixed in Maintenance Release:
Platforms:

Description

In private email, Johann Schinnerl reports

             at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:161) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:79) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.exist.http.urlrewrite.Forward.doRewrite(Forward.java:51) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.http.urlrewrite.XQueryURLRewrite.doRewrite(XQueryURLRewrite.java:525) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.http.urlrewrite.XQueryURLRewrite.service(XQueryURLRewrite.java:344) ~[exist-core-5.2.0.jar:5.2.0]
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
             at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1386) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226) ~[websocket-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:566) ~[jetty-security-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485) ~[jetty-servlet-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:767) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.Server.handle(Server.java:500) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) ~[jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) [jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) [jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270) [jetty-server-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [jetty-io-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [jetty-io-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [jetty-io-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) [jetty-util-9.4.26.v20200117.jar:9.4.26.v20200117]
             at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) [jetty-util-9.4.26.v20200117.jar:9.4.26.v20200117]
             at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222-4-redhat]
Caused by: java.lang.NullPointerException
             at net.sf.saxon.functions.SystemProperty.getProperty(SystemProperty.java:129) ~[saxon9pe.jar:?]
             at net.sf.saxon.functions.SystemProperty.call(SystemProperty.java:86) ~[saxon9pe.jar:?]
             at net.sf.saxon.functions.SystemProperty.call(SystemProperty.java:31) ~[saxon9pe.jar:?]
             at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:532) ~[saxon9pe.jar:?]
             at net.sf.saxon.expr.Expression.evaluateItem(Expression.java:846) ~[saxon9pe.jar:?]
             at net.sf.saxon.expr.parser.Evaluator$6.evaluate(Evaluator.java:213) ~[saxon9pe.jar:?]
             at net.sf.saxon.expr.SystemFunctionCall.evaluateArguments(SystemFunctionCall.java:446) ~[saxon9pe.jar:?]
             at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:530) ~[saxon9pe.jar:?]
             at net.sf.saxon.style.UseWhenFilter.evaluateStatic(UseWhenFilter.java:666) ~[saxon9pe.jar:?]
             at net.sf.saxon.style.UseWhenFilter.processStaticVariable(UseWhenFilter.java:376) ~[saxon9pe.jar:?]
             at net.sf.saxon.style.UseWhenFilter.startElement(UseWhenFilter.java:209) ~[saxon9pe.jar:?]
             at net.sf.saxon.event.StartTagBuffer.startContent(StartTagBuffer.java:246) ~[saxon9pe.jar:?]
             at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177) ~[saxon9pe.jar:?]
             at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177) ~[saxon9pe.jar:?]
             at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:446) ~[saxon9pe.jar:?]
             at org.exist.util.serializer.ReceiverToSAX.startElement(ReceiverToSAX.java:105) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.XIncludeFilter.startElement(XIncludeFilter.java:233) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.NativeSerializer.serializeToReceiver(NativeSerializer.java:271) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.NativeSerializer.serializeToReceiver(NativeSerializer.java:273) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.NativeSerializer.serializeToReceiver(NativeSerializer.java:130) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.Serializer.toSAX(Serializer.java:856) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.xslt.StylesheetResolverAndCompiler.compileTemplates(StylesheetResolverAndCompiler.java:149) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.xslt.StylesheetResolverAndCompiler.templates(StylesheetResolverAndCompiler.java:99) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.xslt.StylesheetResolverAndCompiler.newTransformerHandler(StylesheetResolverAndCompiler.java:127) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.xquery.functions.transform.Transform.createHandler(Transform.java:384) ~[exist-core-5.2.0.jar:5.2.0]
             ... 74 more

Johann Schinnerl

to which I responded

Well, it certainly takes us a big step forward, but it doesn't actually solve it.

At the time of the crash, we're evaluating a call on the system-property() function that appears probably in the select expression of a static variable. The code in question is

Configuration config = rsc.getConfiguration();
String edition = rsc.getPackageData().getTargetEdition();
where rsc is the RetainedStaticContext of the expression (the function call), and it's telling us that the RetainedStaticContext exists but has no PackageData. Now we have to work out why, which ain't easy.

The line numbers in UseWhenFilter are slightly out from my version; the commit log points to bugs 4326 and 4546, but neither seems directly relevant.

The stack trace shows

at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177) ~[saxon9pe.jar:?]
             at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:446) ~[saxon9pe.jar:?]
             at org.exist.util.serializer.ReceiverToSAX.startElement(ReceiverToSAX.java:105) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.XIncludeFilter.startElement(XIncludeFilter.java:233) ~[exist-core-5.2.0.jar:5.2.0]
             at org.exist.storage.serializers.NativeSerializer.serializeToReceiver(NativeSerializer.java:271) ~[exist-core-5.2.0.jar:5.2.0]

which implies that the stylesheet content is being piped directly into Saxon via SAX events, and this suggests that the initialization is incomplete in some way. I guess the most likely way they do this is via the JAXP TemplatesHandler interface. The TemplatesHandlerImpl initialization does

UseWhenFilter useWhenFilter = new UseWhenFilter(compilation, builder, NestedIntegerValue.TWO);

The third argument is the import precedence and I've no idea why this is set to 2! But this doesn't feel relevant.

More to the point, the "compilation" object that's being passed in here doesn't have its PackageData initialized and this could well account for the subsequent NPE. So I guess I need to do some tests of the JAXP TemplatesHandler using 3.0 constructs that access package data.

I'll raise an issue.

Michael Kay Saxonica

reported against 9.9.1.5

Actions #1

Updated by Michael Kay over 3 years ago

Created a new JUnit test JAXPTests/TemplatesHandlerTest/testTemplatesHandlerStaticExpressions which reproduces the problem (thereby confirming that the problem is with TemplatesHandler and static context).

Actions #2

Updated by Michael Kay over 3 years ago

Adding the line

compilation.setMinimalPackageData();

to the initialization of TemplatesHandlerImpl fixes the issue.

Actions #3

Updated by Michael Kay over 3 years ago

  • Status changed from New to Resolved
  • Applies to branch 10, trunk added
  • Fix Committed on Branch 10, 9.9, trunk added

Patch committed

Actions #4

Updated by O'Neil Delpratt over 3 years ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.2 added

Bug fix applied in the Saxon 10.2 maintenance release.

Actions #5

Updated by O'Neil Delpratt over 3 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.9.1.8 added

Bug fix applied on the Saxon 9.9.1.8 maintenance release.

Please register to edit this issue

Also available in: Atom PDF