From 52386acea01b8ef1e926c7ffa89ff916a4fa433c Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Fri, 9 Jan 2026 10:33:16 +0530 Subject: [PATCH 1/2] Trigger property change when setting undefined value explicitly to NaN --- core/src/org/sbml/jsbml/AbstractTreeNode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/org/sbml/jsbml/AbstractTreeNode.java b/core/src/org/sbml/jsbml/AbstractTreeNode.java index 63bc6c716..9d82b5f3f 100644 --- a/core/src/org/sbml/jsbml/AbstractTreeNode.java +++ b/core/src/org/sbml/jsbml/AbstractTreeNode.java @@ -437,7 +437,8 @@ public void firePropertyChange(String propertyName, Object oldValue, changeType = 0; // element added } else if ((oldValue != null) && (newValue == null)) { changeType = 1; // element removed - } else if ((oldValue != null) && !oldValue.equals(newValue)) { + } else if ((oldValue != null) && + (!oldValue.equals(newValue) || oldValue != newValue)) { changeType = 2; // real property change } if (-1 < changeType) { From 26746e4b18ccfd9b64faece70195f5323e179c30 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Thu, 12 Mar 2026 16:21:18 +0530 Subject: [PATCH 2/2] Add NaN property-change regression test using SimpleTreeNodeChangeListener (#273) --- .../jsbml/test/PropertyChangeNaNTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 core/test/org/sbml/jsbml/test/PropertyChangeNaNTest.java diff --git a/core/test/org/sbml/jsbml/test/PropertyChangeNaNTest.java b/core/test/org/sbml/jsbml/test/PropertyChangeNaNTest.java new file mode 100644 index 000000000..e06b83983 --- /dev/null +++ b/core/test/org/sbml/jsbml/test/PropertyChangeNaNTest.java @@ -0,0 +1,67 @@ +/* + * ---------------------------------------------------------------------------- + * This file is part of JSBML. Please visit + * for the latest version of JSBML and more information about SBML. + * + * Copyright (C) 2009-2022 jointly by the following organizations: + * 1. The University of Tuebingen, Germany + * 2. EMBL European Bioinformatics Institute (EBML-EBI), Hinxton, UK + * 3. The California Institute of Technology, Pasadena, CA, USA + * 4. The University of California, San Diego, La Jolla, CA, USA + * 5. The Babraham Institute, Cambridge, UK + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation. A copy of the license agreement is provided + * in the file named "LICENSE.txt" included with this software distribution + * and also available online as . + * ---------------------------------------------------------------------------- + */ + +package org.sbml.jsbml.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.sbml.jsbml.Parameter; +import org.sbml.jsbml.util.SimpleTreeNodeChangeListener; +import org.sbml.jsbml.util.TreeNodeChangeEvent; + +/** + * Tests for property-change events when working with NaN values. + * + * This is a regression test for PR #273: + * when a double property is internally stored as NaN and is explicitly + * set to NaN again, a property-change event should be fired. + */ +public class PropertyChangeNaNTest { + + private static class CountingListener extends SimpleTreeNodeChangeListener { + int count = 0; + + public void propertyChange(TreeNodeChangeEvent evt) { + count++; + } + } + + @Test + public void firesPropertyChangeWhenUndefinedDoubleSetToNaN() { + // Parameter value defaults to "undefined", which is internally represented as NaN. + Parameter p = new Parameter(3, 1); + + CountingListener listener = new CountingListener(); + p.addTreeNodeChangeListener(listener); + + // Sanity check: value is NaN before we start. + assertTrue(Double.isNaN(p.getValue())); + + // Explicitly set the value to NaN again. + listener.count = 0; + p.setValue(Double.NaN); + + // With the fix in AbstractTreeNode.firePropertyChange, this should now + // be treated as a real property change and fire exactly one event. + assertEquals(1, listener.count); + } +} \ No newline at end of file