Project

Profile

Help

Bug #4422

closed

java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.tree.tiny.TinyTree.getCharacterBuffer()

Added by Pranay Deshpande over 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2020-01-13
Due date:
% Done:

0%

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

Description

Dear Colleagues,

This is Pranay from SAP Labs. We are using SaxonEE library for XSLT processing in our product. Where we are getting below exception, when huge payload is sent for XPath evaluation.

java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.tree.tiny.TinyTree.getCharacterBuffer() of a null object loaded from local variable 'tt'

We are getting this issue in SaxonEE-9.9 version

PS: We are getting this issue only if the XML payload is huge. For smaller payload, its working fine.

Could you please provide us some insight into this problem. Is it a known issue, can we expect a fix for this in the upcoming releases, or is there any other way to avoid this.

In our stack, we have Apache Camel in our runtime, SaxonEE as XSLT processor with OSGI (Karaf containers)

Thanks in advance Best Regards, Pranay Deshpande SAP Labs

Actions #1

Updated by Michael Kay over 4 years ago

This is not a known problem, so we would need to reproduce it in order to create a fix.

However, there are known problems running Saxon in an OSGi environment. See for example your previous (unresolved) issue #4213 (and others found by searching for OSGi). However, OSGi could be a red herring here; it would be good to see if the problem can be reproduced without OSGi. Clearly, paths in the code involving exceptionally large XML trees are not going to be exercised as thoroughly in our test suites, so a bug in this area is by no means impossible.

Is there a stack trace?

From the information supplied, it looks as if it's happening during TinyBuilder.makeTextNode() and it's hard to see anything on that path that would be sensitive to the data size. But usually with bugs like this, the only way to solve them is to first reproduce them.

Actions #2

Updated by Michael Kay over 4 years ago

One additional observation is that with "huge" XML files, over a gigabyte, we start to hit built-in Java limits on the sizes of strings and arrays. We circumvent some of these limits, for example by holding the character content of a large document as an array of arrays, but we can't work around them all. It's very likely, for example, that either Saxon or the underlying XML parser will crash if a single text node exceeds the maximum size of a Java string. Apart from the problem that Saxon can't solve these problems on its own, because they involve dependencies, there is also a problem that testing documents of this size comprehensively becomes very impractical.

Having said that, the symptoms you have described don't suggest that this is the problem in this particular case.

Actions #3

Updated by Pranay Deshpande over 4 years ago

Hi Michael,

As the issue is not consistently reproducible, we don't have detailed stack traces for this. Could you figure out from the provided error log, what could be the probable reason for this issue?

Also, wanted to know is the TinyTree mechanism is part of some performance optimization mechanism by Saxon? And if that's the case can we turn that feature Off by some mechanism? Because we have never seen this issue for any other customer before and also with an XML payload <1mb (approx), we are not getting this issue.

-Pranay

Actions #4

Updated by Michael Kay over 4 years ago

I would hate to walk away from this problem without solving it, but if it's not reproducible "in the lab" then our chances of solving it (& testing a solution!) are very low. The use of OSGi may be completely irrelevant, but it's always a cause for suspicion.

Certainly, you can try to run with a different tree model, such as Saxon's Linked Tree. It will probably use quite a bit more memory, but should work. You can choose the tree model used for building each document; the details depend on what API you are using to construct the tree.

I've looked again carefully at the code in this area, and I can't see anything wrong that would trigger these symptoms.

Do you happen to know whether the document is large because it contains many small text nodes, or if it contains a small number of very large text nodes? If we knew something of the profile, we could at least attempt some testing.

Actions #5

Updated by Michael Kay about 4 years ago

  • Category set to Internals
  • Status changed from New to Closed
  • Assignee set to Michael Kay
  • Priority changed from High to Normal

Closing this reluctantly without a resolution, because we do not have a repro that we can investigate.

If you can show us how to reproduce the problem, please re-open the bug.

Actions #6

Updated by Pranay Deshpande about 4 years ago

Hi Michael,

We are still facing this issue and below are the detailed traces:

java.lang.NullPointerException: while trying to invoke the method net.sf.saxon.tree.tiny.TinyTree.getCharacterBuffer() of a null object loaded from local variable 'tt' at net.sf.saxon.tree.tiny.TinyBuilder.makeTextNode(TinyBuilder.java:427) at net.sf.saxon.tree.tiny.TinyBuilder.characters(TinyBuilder.java:406) at net.sf.saxon.event.ProxyReceiver.characters(ProxyReceiver.java:193) at net.sf.saxon.event.ReceivingContentHandler.flush(ReceivingContentHandler.java:646) at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:364) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:155) at org.apache.cxf.staxutils.StaxSource.parse(StaxSource.java:268) at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:434) at net.sf.saxon.event.Sender.send(Sender.java:141) at net.sf.saxon.Configuration.buildDocumentTree(Configuration.java:4237) at net.sf.saxon.expr.JPConverter$FromSource.convert(JPConverter.java:608) at net.sf.saxon.expr.JPConverter$FromSource.convert(JPConverter.java:598) at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:173)

Could you please give us some hints on what could be the possible root cause of this issue. I can send you the payload XML and the Xpaths the user is trying to evaluate, over the mail.

Regards Pranay

Actions #7

Updated by Michael Kay about 4 years ago

  • Status changed from Closed to In Progress

Thanks for the extra info. The stack trace shows that the parser feeding data to Saxon's tree builder is an Apache Camel class. This has given problems in the past: see https://stackoverflow.com/questions/60103194/nullpointerexception-at-net-sf-saxon-event-receivingcontenthandler-startprefixma/60113236#60113236 which refers to a known Camel bug https://issues.apache.org/jira/browse/CAMEL-10704

Please check that you are using a version of Camel in which this bug is fixed.

The symptoms in this case are a little different, so it could be the same bug, or a different bug in the same general area; the Saxon ReceivingContentHandler, which receives data from the XML parser, tends to crash if the input from the parser is not precisely conformant to the requirements of the SAX specification.

I'm reluctant to go down a route where we have to run Saxon under Camel in order to reproduce and diagnose this failure, especially as any fix will almost certainly be in Camel rather than Saxon code. Sending us the XML and XPath won't be any use, because the problem is (I'm 99% sure) not with the XML itself, but with the way the Camel parser is delivering it.

Looking more closely at the code that's failing, it seems likely that the Camel parser is calling startElement() in the ContentHandler without having first called startDocument(). I can't imagine it's always doing that, because Saxon would then always fail this way. There must be some circumstance in which it does this, and finding out these circumstances depends on looking at Apache Camel code. It's odd though that it should depend on the source document size.

There's a version of the relevant Camel module at https://alvinalexander.com/java/jwarehouse/apache-cxf/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java.shtml - I've no idea how current that it is, but it shows that it's essentially a Stax-to-SAX bridge, and it will only send a startDocument() event to Saxon if it's notified of a START_DOCUMENT event by the underlying Stax parser. We can't see from the stack trace what that Stax parser might be but Stax parsers are known to be a bit variable; the spec isn't too rigorous and there are different interpretations of it.

I think this is a product integration problem where the Apache Camel people are probably better placed to solve it than we are. We'll be happy to work with them, but I think they should lead. Please check first that you are using latest versions and that it isn't a known bug.

Actions #8

Updated by Michael Kay about 4 years ago

I note this comment in Saxon's StaxBridge class, which accepts input from a StAX parser:

        if (currentEvent == START_OF_INPUT) {
            // StAX isn't reporting START_DOCUMENT so we supply it ourselves
            currentEvent = START_DOCUMENT;
            return currentEvent;
        }

This code is clearly written to cope with a situation where a Stax parser doesn't report the START_DOCUMENT event, so we know this is something that can happen.

The Javadoc for XMLStreamReader doesn't actually say whether you are guaranteed to see a START_DOCUMENT event. By contrast the SAX ContentHandler javadoc makes it pretty clear that the ContentHandler can expect to see one.

Actions #9

Updated by Michael Kay about 4 years ago

  • Status changed from In Progress to Resolved

I am closing this because as far as I am able to determine, this is an Apache Camel bug: its Stax-to-SAX bridge, as far as I can tell, is issuing a SAX startElement() call with no preceding startDocument(); this is contrary to the SAX specification and Saxon falls over when it receives incorrect SAX input (the interface is performance-critical so we trust the client to make a valid sequence of calls).

Actions #10

Updated by O'Neil Delpratt about 2 years ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF