pjfanning opened a new pull request, #125:
URL: https://github.com/apache/poi-xmlbeans/pull/125

   Fixes https://issues.apache.org/jira/browse/XMLBEANS-676
   
   Ways the `NamespaceContext` thread-local could be left holding memory:
   
   - `getCurrent()` created and stored a stack when none existed. 
`JavaQNameHolder`/`JavaNotationHolderEx` call it outside any push/pop, so the 
stack was never removed.
   - `NamespaceContextStack.pop()` set `current` and shrank the stack in two 
separate steps. An exception between them (e.g. from `Thread.stop`) left them 
out of step, so the stack never emptied and the thread-local kept a stale 
`current` (a `TypeStore` holding the whole document's store).
   - `SchemaParticleImpl` and `SchemaLocalAttributeImpl` called `push` inside 
the `try`, so a failed push (e.g. OOM) still ran `pop` and removed the caller's 
frame. On an empty stack `pop` threw `IndexOutOfBoundsException`, which hid the 
original error.
   
   Changes:
   - `getCurrent()` returns `null` without creating state
   - `pop()` uses a single `stack.remove(...)`; an unbalanced pop cleans up 
instead of throwing
   - `ThreadLocal.remove()` instead of `set(null)` when the stack empties
   - `push` moved before the `try` in the two schema classes
   - new `NamespaceContextTest`
   
   This can't protect against `Thread.stop` landing between a caller's `push` 
and its `try`. Callers in that situation should use 
`ThreadLocalUtil.clearAllThreadLocals()`.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to