Repository navigation
[XMLBEANS-676] avoid NamespaceContext thread-local leaks - #125
Merged
pjfanning merged 1 commit intoOct 4, 2026
Merged
Conversation
- getCurrent() no longer creates thread-local state that is never removed - pop() updates current and the stack in one step and tolerates an unbalanced pop instead of throwing (which masked the original exception) - remove() the thread-local when the stack empties - push before the try in SchemaParticleImpl/SchemaLocalAttributeImpl so a failed push does not pop the caller's frame Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
None of the problems fixed here are recent regressions. They all go back to the original code:
XMLBEANS-502 (d1a3f12) added |
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.
Fixes https://issues.apache.org/jira/browse/XMLBEANS-676
Ways the
NamespaceContextthread-local could be left holding memory:getCurrent()created and stored a stack when none existed.JavaQNameHolder/JavaNotationHolderExcall it outside any push/pop, so the stack was never removed.NamespaceContextStack.pop()setcurrentand shrank the stack in two separate steps. An exception between them (e.g. fromThread.stop) left them out of step, so the stack never emptied and the thread-local kept a stalecurrent(aTypeStoreholding the whole document's store).SchemaParticleImplandSchemaLocalAttributeImplcalledpushinside thetry, so a failed push (e.g. OOM) still ranpopand removed the caller's frame. On an empty stackpopthrewIndexOutOfBoundsException, which hid the original error.Changes:
getCurrent()returnsnullwithout creating statepop()uses a singlestack.remove(...); an unbalanced pop cleans up instead of throwingThreadLocal.remove()instead ofset(null)when the stack emptiespushmoved before thetryin the two schema classesNamespaceContextTestThis can't protect against
Thread.stoplanding between a caller'spushand itstry. Callers in that situation should useThreadLocalUtil.clearAllThreadLocals().🤖 Generated with Claude Code