From 9c7c2f929be24f398491196741455c402609466a Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Fri, 30 Jan 2026 09:45:27 +0530 Subject: [PATCH] Avoid NPE in ExpandFunctionDefinitionConverter when expanding arguments --- .../ExpandFunctionDefinitionConverter.java | 13 +- .../jsbml/AssignmentRuleDerivedUnitsTest.java | 50 + .../sbml/jsbml/testdata/BIOMD0000000327.xml | 1055 +++++++++++++++++ 3 files changed, 1114 insertions(+), 4 deletions(-) create mode 100644 core/test/org/sbml/jsbml/AssignmentRuleDerivedUnitsTest.java create mode 100644 core/test/org/sbml/jsbml/testdata/BIOMD0000000327.xml diff --git a/core/src/org/sbml/jsbml/util/converters/ExpandFunctionDefinitionConverter.java b/core/src/org/sbml/jsbml/util/converters/ExpandFunctionDefinitionConverter.java index 248611ad7..9027c4392 100644 --- a/core/src/org/sbml/jsbml/util/converters/ExpandFunctionDefinitionConverter.java +++ b/core/src/org/sbml/jsbml/util/converters/ExpandFunctionDefinitionConverter.java @@ -237,11 +237,16 @@ public boolean accepts(Object o) { ASTNode current = (ASTNode) o; if (current.equals(bvar)) { - ASTNode parent = (ASTNode) current.getParent(); - int index = parent.getIndex(current); + TreeNode parentNode = current.getParent(); - if (index != -1) { - parent.replaceChild(index, expandedBVar); + // Only attempt replacement if the parent is a non-null ASTNode + if (parentNode instanceof ASTNode) { + ASTNode parent = (ASTNode) parentNode; + int index = parent.getIndex(current); + + if (index != -1) { + parent.replaceChild(index, expandedBVar); + } } } } diff --git a/core/test/org/sbml/jsbml/AssignmentRuleDerivedUnitsTest.java b/core/test/org/sbml/jsbml/AssignmentRuleDerivedUnitsTest.java new file mode 100644 index 000000000..a1a778686 --- /dev/null +++ b/core/test/org/sbml/jsbml/AssignmentRuleDerivedUnitsTest.java @@ -0,0 +1,50 @@ +package org.sbml.jsbml; + +import static org.junit.Assert.*; + +import java.io.File; +import java.net.URL; + +import org.junit.Test; + +public class AssignmentRuleDerivedUnitsTest { + + /** + * Regression test for issue #268. + * Calling getDerivedUnits() on an AssignmentRule in BIOMD0000000327.xml + * should not throw a NullPointerException. + */ + @Test + public void testGetDerivedUnitsDoesNotThrowNPE() throws Exception { + // Load the example model from test resources + ClassLoader cl = getClass().getClassLoader(); + URL url = cl.getResource("org/sbml/jsbml/testdata/BIOMD0000000327.xml"); + assertNotNull("Test SBML file not found on classpath", url); + + SBMLDocument doc = new SBMLReader().readSBML(new File(url.toURI())); + Model model = doc.getModel(); + assertNotNull(model); + + // Find the assignment rule for variable "japl" + AssignmentRule targetRule = null; + for (int i = 0; i < model.getRuleCount(); i++) { + Rule r = model.getRule(i); + if (r instanceof AssignmentRule) { + AssignmentRule ar = (AssignmentRule) r; + if ("japl".equals(ar.getVariable())) { + targetRule = ar; + break; + } + } + } + + assertNotNull("AssignmentRule for variable 'japl' not found", targetRule); + + // The call to getDerivedUnits() must not throw a NullPointerException + try { + targetRule.getDerivedUnits(); + } catch (NullPointerException npe) { + fail("getDerivedUnits() must not throw NullPointerException: " + npe); + } + } +} \ No newline at end of file diff --git a/core/test/org/sbml/jsbml/testdata/BIOMD0000000327.xml b/core/test/org/sbml/jsbml/testdata/BIOMD0000000327.xml new file mode 100644 index 000000000..4b70b9100 --- /dev/null +++ b/core/test/org/sbml/jsbml/testdata/BIOMD0000000327.xml @@ -0,0 +1,1055 @@ + + + + + +

+ A mathematical model of the pancreatic duct cell generating high bicarbonate concentrations in pancreatic juice +
David C Whitcomb, G Bard Ermentrout, Pancreas 2004 29:e30-40; PubMedID:15257112 +

+

+Abstract:
+ OBJECTIVE: + +To develop a simple, physiologically based mathematical model of pancreatic duct cell secretion using experimentally derived parameters that generates pancreatic fluid bicarbonate concentrations of >140 mM after CFTR activation.
+ METHODS: + +A new mathematical model was developed simulating a duct cell within a proximal pancreatic duct and included a sodium-2-bicarbonate cotransporter (NBC) and sodium-potassium pump (NaK pump) on a chloride-impermeable basolateral membrane, CFTR on the luminal membrane with 0.2 to 1 bicarbonate to chloride permeability ratio. Chloride-bicarbonate antiporters (Cl/HCO3 AP) were added or subtracted from the basolateral (APb) and luminal (APl) membranes. The model was integrated over time using XPPAUT.
+ RESULTS: + +This model predicts robust, NaK pump-dependent bicarbonate secretion with opening of the CFTR, generates and maintains pancreatic fluid secretion with bicarbonate concentrations >140 mM, and returns to basal levels with CFTR closure. Limiting CFTR permeability to bicarbonate, as seen in some CFTR mutations, markedly inhibited pancreatic bicarbonate and fluid secretion.
+ CONCLUSIONS: + +A simple CFTR-dependent duct cell model can explain active, high-volume, high-concentration bicarbonate secretion in pancreatic juice that reproduces the experimental findings. This model may also provide insight into why CFTR mutations that predominantly affect bicarbonate permeability predispose to pancreatic dysfunction in humans. +

+

This SBML version of the model was created directly from the XPPAUT code found in the appendix with the exception of the parameter vr, the ratio between the duct cell volume and the duct lumen, which is defined inversely to the main text in the XPPAUT code. vr was defined as the ratio of the duct cell volume to the duct lumen volume as in the main text. The model reproduces the figures found in the article. The model uses initial assignments for the lumen volume and events to trigger CFTR opening, so only tools supporting these features can be used to simulate it (eg. Copasi and SBW/Roadrunner).

+ +
+ + + + + + + + Endler + Lukas + + lukas@ebi.ac.uk + + EMBL-EBI + + + + + Smallbone + Kieran + + kieran.smallbone@manchester.ac.uk + + University of Manchester + + + + + + 2011-04-14T00:00:00Z + + + 2016-04-08T16:59:34Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ao + + + ai + + + bo + + + bi + + + ka + + + kb + + + + + + + + ao + bi + + + + bo + ai + + + + + ka + kb + + + + + + + 1 + + + ai + ka + + + + bi + kb + + + + + + + ao + ka + + + + bo + kb + + + + + + + + 1 + + + ao + ka + + + + bo + kb + + + + + + + ai + ka + + + + bi + kb + + + + + + + + + + + + + + xi + + + xo + + + + + + xi + xo + + + + + xi + xo + + + + + + xi + xo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + gcftrbase + + + + + + + cell + vr + + + + + + + + + + 160 + bl + + + + + + + + + + + + r + temp + + f + + + + + + bi + bl + + + + + + + + + + + + + + r + temp + + f + + + + + + + + + + bi + 2 + + ni + + + + + + bb + 2 + + nb + + + + + + + + + + + + + + + r + temp + + f + + + + + + ci + cl + + + + + + + + + + + + + + r + temp + + f + + + + + + nb + ni + + + + + + + + + + + g + ci + cl + + gcftr + g_cl + + + + + + + + + g + bi + bl + + gcftr + g_bi + + + + + + gnbc + + + + + + + + + + + knbc + enbc + + + + kbcf + eb + + + + kccf + ec + + + + gk + ek + + + + gnaleak + ena + + + + + knbc + kbcf + kccf + gk + + + + + + + + + knbc + + + v + enbc + + + + + + + + + kbcf + + + v + eb + + + + + + + + + kccf + + + v + ec + + + + + + + + + + ap + bl + bi + cl + ci + kbi + kcl + + gapl + + + + + + + + + ap + bb + bi + cb + ci + kbi + kcl + + gapbl + + + + + + + + + + + + + + + + jccftr + jbcftr + + + vr + + + + jac + + + 1 + rat + + + + ionstr + + + + + + + + gnak + + + v + epump + + + + + + ni + np0 + + 3 + + + + + + + + + gnaleak + + + v + ena + + + + + + + + + + + + + + + + + + + + cell + zeta + japl + + + + + + + + + + + + + + + + cell + zeta + jbcftr + + + + + + + + + + + + + + + + cell + zeta + jccftr + + + + + + + + + + + + + + + + + + cell + zeta + japl + + + + + + + + + + + + + + + + + + cell + zeta + japbl + + + + + + + + + + + + + + + + cell + zeta + jnak + + + + + + + + + + + + + + + + cell + zeta + jnaleak + + + + + + + + + + + + + cell + zeta + buf + + + bi0 + bi + + + + + + + + + + + + + + lumen + zeta + jac + rat + + + + + + + + + + + + + lumen + zeta + jac + + + + + + + + + + + + + lumen + zeta + jlum + bl + + + + + + + + + + + + t + ton + + + + + + + gcftron + + + + + + + + + + t + toff + + + + + + + gcftrbase + + + + + +
+
\ No newline at end of file