Web / Apache Axiom Interview questions
What happens when you call getNextOMSibling() before the tree is fully built?
Nothing breaks by design - this is exactly the scenario deferred building is meant to handle. If the sibling reference is currently null and the parent isn't yet marked complete, the call transparently pulls additional StAX events from the underlying builder until either the sibling node materializes or the parent's closing tag is reached (meaning there genuinely is no further sibling).
From the caller's point of view, the method simply returns the next sibling, or null if there isn't one - the fact that more parsing happened behind the scenes as a side effect of that single method call is invisible unless you're specifically instrumenting or profiling it.
Where this can actually cause trouble is if the underlying XMLStreamReader has already been closed or fully consumed by that point - for example, after an earlier serializeAndConsume() call on the same or an overlapping stream - in which case the builder can't pull further events, and the call is likely to raise an exception (commonly surfacing as something like an OMException or IllegalStateException) rather than returning cleanly.
So the safe mental model is: navigation methods on an unbuilt tree are fine and expected as long as the underlying stream is still available to be read from; they become a problem specifically once that stream has already been drained or closed.
More Related questions...