Fix NPE in XMLHandlerImpl.dispose caused by concurrent DOM serialization#91
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenICF/sessions/dd83ece1-f572-4dea-8b5e-958430aa6c51 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
vharseko
May 14, 2026 12:14
View session
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.
Problem
OpenICFProvisionerService.getStatus→ connectortest()→XMLConnector.disposeproduced:Root cause
ConcurrentXMLHandler.init()/dispose()mutated theinvokersreference counter and calledproxy.dispose()under a shared read lock. Two threads could simultaneously decrement to zero and run the DOM serialization in parallel on the sameDocument. Saxon'sDOMSenderwalksNodeList.item(i)aftergetLength(); a concurrentremoveChild(from the empty-text-node cleanup or another in-flight transform) makesitem(i)returnnullfor a still-in-range index, producing the NPE.Fix
ConcurrentXMLHandler.init()/dispose()now use the write lock, so the lifecycle counter andproxy.dispose()cannot race against each other or againstsearch/authenticateread-lock walks of the same DOM.XMLHandlerImpl.dispose()is hardened:NodeListis snapshotted into aList<Node>before mutating the DOM.removeChild.synchronized (document)as defense-in-depth.FileOutputStreamis now closed in afinallyblock.XMLConnector.dispose()already nulls outxmlInstanceHandlerafter disposal, so a seconddispose()from upper layers is already a safe no-op (no change needed).Validation
mvn -ntp testinOpenICF-xml-connector: 81/81 tests pass.Fixes the
Cannot invoke "org.w3c.dom.Node.getNodeType()" because "child" is nullreported in the issue.