Release the Locale when a SAX load is abandoned - #117
Merged
Conversation
SaxLoader.postLoad() nulls _locale and _context - "fix garbage collection of Locale -> Xobj -> STL" - but it only runs when the parse completes. Every failure path leaves both set: the four catch blocks abort the context and rethrow without clearing them, and an IOException out of _xr.parse() is not caught at all, so it does not even abort. The XMLReader holds the SaxLoader as its content, DTD, error, lexical and declaration handler. With a caller-supplied reader (XmlOptions.setLoadUseXMLReader) that reader outlives the parse, so a failed load pins the partly built document and its SchemaTypeLoader until the next parse on that reader. Abort and clear from a finally instead, which also covers the IOException path. The per-catch _context.abort() calls go away, and the RuntimeException catch existed only to abort before rethrowing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SaxLoader.postLoad()exists to drop the loader's references to the document it just built:It only runs when the parse completes. Every failure path leaves both fields set — the four catch blocks call
_context.abort()and rethrow without clearing them, and anIOExceptionout of_xr.parse(is)is not caught at all, so it does not even abort.That matters because the
XMLReaderholds theSaxLoaderas its content, DTD, error, lexical and declaration handler. When xmlbeans creates the reader itself the loader becomes garbage anyway, butXmlOptions.setLoadUseXMLReader(...)lets a caller supply a reader that outlives the parse — and callers reuseXmlOptions. A failed load then pins the partly built document and itsSchemaTypeLoaderon that reader until the next parse, which is exactly theLocale -> Xobj -> STLchain the comment above is about.This aborts and clears from a
finally, which also covers the previously uncaughtIOExceptionpath. The per-catch_context.abort()calls go away, and thecatch (RuntimeException e)block existed only to abort before rethrowing, so it goes too.Added
SaxLoaderAbortTest: it supplies its ownXMLReader, parses, then reflects on the reader's content handler to check_localeand_contextare cleared. The two failure cases fail on trunk and pass with this change; the success case passes either way and pins the existingpostLoadbehaviour.Full suite: 3173 tests pass (170 skipped).
🤖 Generated with Claude Code