Skip to content

Fix NPE in XMLConnector.dispose() when init() failed#2

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-null-pointer-exception
Draft

Fix NPE in XMLConnector.dispose() when init() failed#2
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-null-pointer-exception

Conversation

Copy link
Copy Markdown

Copilot AI commented May 8, 2026

When XMLConnector.init() fails (e.g. invalid XML/XSD path), the framework still invokes dispose(), which dereferences the never-assigned xmlInstanceHandler and throws an NPE that masks the original failure cause from test/operation calls.

Changes

  • XMLConnector.dispose(): guard against xmlInstanceHandler == null, log at ok level and return instead of throwing.
  • Idempotency: null out xmlInstanceHandler in a finally after dispose() so repeated calls are safe (consistent with ConcurrentXMLHandler.dispose() decrementing invokers).
  • Logging: guard the config.getXmlFilePath() access so a pre-init dispose can't NPE either.
public void dispose() {
    if (xmlInstanceHandler == null) {
        log.ok("Dispose called but XML handler was not initialized; nothing to release");
        return;
    }
    try {
        xmlInstanceHandler.dispose();
    } finally {
        xmlInstanceHandler = null;
    }
    log.ok("Dispose {0}", config != null ? config.getXmlFilePath() : null);
}

Notes

Aligns with the Connector#dispose() SPI contract (must tolerate failed init and repeated calls). mvn test was not run locally — the sandbox cannot resolve the opendj-parent:5.1.1-SNAPSHOT parent POM from central.sonatype.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants