Skip to content

Conversation

@dyrpsf
Copy link

@dyrpsf dyrpsf commented Jan 6, 2026

This PR fixes a NullPointerException that could occur when cloning AbstractTreeNode (and thus ASTNode) when userObjects is null.

Previously, the copy constructor in AbstractTreeNode did:

if (anode.isSetUserObjects()) {
userObjects = new HashMap<Object, Object>();
userObjects.putAll(anode.userObjects);
}

If a subclass overrides isSetUserObjects() (e.g. ASTNode) and returns true even when the underlying userObjects map is still null, putAll throws an NPE.

The constructor is now changed to check the field directly:

if (anode.userObjects != null && !anode.userObjects.isEmpty()) {
userObjects = new HashMap<Object, Object>(anode.userObjects);
}

This makes the clone logic robust to such overrides.
I verified the fix by:

Building JSBML and running its tests locally.
Building SBSCL 2.1.1 against this JSBML snapshot.
Running the SBMLTestSuite wrapper used in draeger-lab/SBSCL#74 without encountering the previous NPE in ASTNode.clone.
Related issues:

Fixes #258
Related to draeger-lab/SBSCL#74

@draeger
Copy link
Member

draeger commented Jan 6, 2026

I am wondering if this is actually a bug in JSBML? If so, shouldn't it be fixed there?

@luciansmith
Copy link
Member

This is jsbml? Unless I'm missing something?

@draeger
Copy link
Member

draeger commented Jan 6, 2026

This is jsbml? Unless I'm missing something?

Yes, there were several edits on SBSCL. I'll check this PR here, of course.

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.

NullPointerException in ASTNode

3 participants