NullPointerException in com.saxonica.pull.TreeWalker
Gunther Rademacher reports on the saxon-help list:
I have a piece of code that worked with Saxon-EE 9.5, but throws a NPE with 9.6. It
uses PullToStax and TreeWalker to get Stax events from a DOM source.
A complete reproduction is shown below.
In the actual application, different types of sources are mapped to Stax events, for
peeking at some initial fragment of those sources. PullToStax came in handy to
accomplish this for DOM sources. I might of course implement that differently.
Concerning PullToStax and TreeWalker, I am not sure whether they are considered
part of the official API. I may also be misusing them in some way. Should I possibly
give up this approach?
#1 Updated by Michael Kay almost 5 years ago
- Status changed from New to Resolved
Thanks for reporting it. I've added your test case as a JUnit test and have produced a patch which will be committed on the 9.6 and 9.7 branches.
This code hasn't changed substantially for quite a while, but it was affected by a change to the SequenceIterator interface, and the change was made incorrectly. The general principle now is that SequenceIterator no longer maintains the values of position() and current(), and anyone who needs access to these values needs to wrap the SequenceIterator in a FocusTrackingIterator. It's then important always to call next() on the wrapping FocusTrackingIterator, but the TreeWalker fails to follow this rule and calls next() on the underlying SequenceIterator instead, leavng FocusTrackingIterator.current() set to null.
Please register to edit this issue