Author: ruschein
Date: 2010-07-16 16:11:13 -0700 (Fri, 16 Jul 2010)
New Revision: 20955
Modified:
cytoscape/trunk/src/cytoscape/data/CyAttributesImpl.java
Log:
Fixed an infinite recursion bug when attribute equations reference each other
in a circular dependency.
Modified: cytoscape/trunk/src/cytoscape/data/CyAttributesImpl.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/CyAttributesImpl.java 2010-07-16
22:54:38 UTC (rev 20954)
+++ cytoscape/trunk/src/cytoscape/data/CyAttributesImpl.java 2010-07-16
23:11:13 UTC (rev 20955)
@@ -66,6 +66,7 @@
private Set userNonEditableSet;
private String lastEquationError = null;
+ private Set<String> currentlyActiveAttributes = new TreeSet<String>();
protected static final CyLogger logger =
CyLogger.getLogger(Cytoscape.class);
@@ -1129,6 +1130,13 @@
private Object evalEquation(final String id, final String attribName,
final Equation equation,
final StringBuilder errorMessage)
{
+ if (currentlyActiveAttributes.contains(attribName)) {
+ currentlyActiveAttributes.clear();
+ errorMessage.append("Recursive equation evaluation of
\"" + attribName + "\"!");
+ return null;
+ } else
+ currentlyActiveAttributes.add(attribName);
+
final Collection<String> attribReferences =
equation.getAttribReferences();
final Map<String, IdentDescriptor> nameToDescriptorMap = new
TreeMap<String, IdentDescriptor>();
@@ -1140,6 +1148,7 @@
final Object attribValue = getAttribute(id, attribRef);
if (attribValue == null) {
+ currentlyActiveAttributes.clear();
errorMessage.append("Missing value for
referenced attribute \"" + attribRef + "\"!");
logger.warn("Missing value for \"" + attribRef
+ "\" while evaluating an equation
(ID:" + id
@@ -1150,6 +1159,7 @@
try {
nameToDescriptorMap.put(attribRef, new
IdentDescriptor(attribValue));
} catch (final Exception e) {
+ currentlyActiveAttributes.clear();
errorMessage.append("Bad attribute reference to
\"" + attribRef + "\"!");
logger.warn("Bad attribute reference to \"" +
attribRef
+ "\" while evaluating an equation
(ID:" + id
@@ -1160,8 +1170,11 @@
final Interpreter interpreter = new Interpreter(equation,
nameToDescriptorMap);
try {
- return interpreter.run();
+ final Object result = interpreter.run();
+ currentlyActiveAttributes.remove(attribName);
+ return result;
} catch (final Exception e) {
+ currentlyActiveAttributes.clear();
errorMessage.append(e.getMessage());
logger.warn("Error while evaluating an equation: " +
e.getMessage() + " (ID:"
+ id + ", attribute name:" + attribName +
")");
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.