Skip to content

Commit f9ff71d

Browse files
jcschaffclaude
andcommitted
Validate sbmlName against invalid XML chars on every setter
Add SpeciesContext.fixAndValidateSbmlName as the single chokepoint for all 9 setSbmlName methods (SpeciesContext, Structure, ReactionStep, BioModel, Model.GlobalParameter, AssignmentRule, RateRule, BioEvent, plus existing fixSbmlName fix-only path). The helper rejects C0 control chars and U+FFFD via XmlChars.requireValidAttributeContent, throwing PropertyVetoException so existing UI catch blocks render a friendly error instead of a stack trace. This closes the SBML import → setSbmlName → cached VCML attribute path that produced the un-parseable cached XML observed in BioModels 311226221 and 311875206. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b11bb2b commit f9ff71d

7 files changed

Lines changed: 27 additions & 12 deletions

File tree

vcell-core/src/main/java/cbit/vcell/biomodel/BioModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ public void setName(java.lang.String name) throws java.beans.PropertyVetoExcepti
10141014

10151015
public void setSbmlName(String newString) throws PropertyVetoException{
10161016
String oldValue = this.sbmlName;
1017-
String newValue = SpeciesContext.fixSbmlName(newString);
1017+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
10181018

10191019
fireVetoableChange("sbmlName", oldValue, newValue);
10201020
this.sbmlName = newValue;

vcell-core/src/main/java/cbit/vcell/mapping/AssignmentRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public void setName(String name) {
9999
}
100100
public void setSbmlName(String newString) throws PropertyVetoException {
101101
String oldValue = this.sbmlName;
102-
String newValue = SpeciesContext.fixSbmlName(newString);
103-
102+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
103+
104104
fireVetoableChange("sbmlName", oldValue, newValue);
105105
this.sbmlName = newValue;
106106
firePropertyChange("sbmlName", oldValue, newValue);

vcell-core/src/main/java/cbit/vcell/mapping/BioEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ public void setName(String newValue) throws PropertyVetoException {
384384
}
385385
public void setSbmlName(String newString) throws PropertyVetoException {
386386
String oldValue = this.sbmlName;
387-
String newValue = SpeciesContext.fixSbmlName(newString);
388-
387+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
388+
389389
fireVetoableChange("sbmlName", oldValue, newValue);
390390
this.sbmlName = newValue;
391391
firePropertyChange("sbmlName", oldValue, newValue);

vcell-core/src/main/java/cbit/vcell/mapping/RateRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public void setName(String name) {
112112
}
113113
public void setSbmlName(String newString) throws PropertyVetoException {
114114
String oldValue = this.sbmlName;
115-
String newValue = SpeciesContext.fixSbmlName(newString);
116-
115+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
116+
117117
fireVetoableChange("sbmlName", oldValue, newValue);
118118
this.sbmlName = newValue;
119119
firePropertyChange("sbmlName", oldValue, newValue);

vcell-core/src/main/java/cbit/vcell/model/Model.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ public void setSbmlId(String newValue) throws PropertyVetoException{
10351035

10361036
public void setSbmlName(String newString) throws PropertyVetoException{
10371037
String oldValue = this.sbmlName;
1038-
String newValue = SpeciesContext.fixSbmlName(newString);
1038+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
10391039

10401040
fireVetoableChange("sbmlName", oldValue, newValue);
10411041
this.sbmlName = newValue;

vcell-core/src/main/java/cbit/vcell/model/SpeciesContext.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
package cbit.vcell.model;
1212

13+
import org.vcell.util.xml.XmlChars;
14+
1315
import java.beans.PropertyChangeEvent;
1416
import java.beans.PropertyChangeListener;
1517
import java.beans.PropertyVetoException;
@@ -299,10 +301,23 @@ public static String fixSbmlName(String newString) {
299301
String newValue = sb.toString();
300302
return newValue;
301303
}
304+
305+
public static String fixAndValidateSbmlName(String newString, Object source) throws PropertyVetoException {
306+
String newValue = fixSbmlName(newString);
307+
if (newValue == null) return null;
308+
try {
309+
XmlChars.requireValidAttributeContent(newValue, "sbmlName");
310+
} catch (IllegalArgumentException ex) {
311+
throw new PropertyVetoException(ex.getMessage(),
312+
new PropertyChangeEvent(source, "sbmlName", null, newValue));
313+
}
314+
return newValue;
315+
}
316+
302317
public void setSbmlName(String newString) throws PropertyVetoException {
303318
String oldValue = this.sbmlName;
304-
String newValue = fixSbmlName(newString);
305-
319+
String newValue = fixAndValidateSbmlName(newString, this);
320+
306321
fireVetoableChange("sbmlName", oldValue, newValue);
307322
this.sbmlName = newValue;
308323
firePropertyChange("sbmlName", oldValue, newValue);

vcell-core/src/main/java/cbit/vcell/model/Structure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public String getSbmlName() {
6868
}
6969
public void setSbmlName(String newString) throws PropertyVetoException {
7070
String oldValue = this.sbmlName;
71-
String newValue = SpeciesContext.fixSbmlName(newString);
72-
71+
String newValue = SpeciesContext.fixAndValidateSbmlName(newString, this);
72+
7373
fireVetoableChange("sbmlName", oldValue, newValue);
7474
this.sbmlName = newValue;
7575
firePropertyChange("sbmlName", oldValue, newValue);

0 commit comments

Comments
 (0)