From: miettinen Date: Mon, 23 Jun 2014 07:00:04 +0000 (+0000) Subject: Error handling for circular dependencies in Sysdyn models: should not throw StackOver... X-Git-Tag: v1.29.0~267 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=6e35f30f014ad74d1a3a87a04f957f787d3b1e47;p=simantics%2Fsysdyn.git Error handling for circular dependencies in Sysdyn models: should not throw StackOverflowErrors anymore (refs #4891). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29682 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java index 27f33a69..7ccc8155 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in + * Copyright (c) 2007, 2012, 2014 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -28,6 +28,7 @@ import org.simantics.sysdyn.representation.utils.RepresentationUtils; * Variability of a variable in system dynamics models. * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public enum Variability { @@ -164,23 +165,28 @@ public enum Variability { * @return Variabilty of a variable */ static public Variability getVariability(IndependentVariable variable) { - if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) { - - /* - * Game experiments cannot use as many parameter variables as normal experiments. - * If a parameter variable is changed, other parameter values depending on that - * parameter value are not automatically changed. - * - * Something of a hack: - * Allow variable references, if there are not incoming dependencies to the variable. - * This enables the use of derived variables for initial values of stocks. - */ - if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty()) - return getVariability(variable, true, null); - else - return getVariability(variable, false, null); - } else { - return getVariability(variable, true, null); + try { + if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) { + + /* + * Game experiments cannot use as many parameter variables as normal experiments. + * If a parameter variable is changed, other parameter values depending on that + * parameter value are not automatically changed. + * + * Something of a hack: + * Allow variable references, if there are not incoming dependencies to the variable. + * This enables the use of derived variables for initial values of stocks. + */ + if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty()) + return getVariability(variable, true, null); + else + return getVariability(variable, false, null); + } else { + return getVariability(variable, true, null); + } + } catch (StackOverflowError e) { + // For circular dependencies; selecting continuous for a good guess. + return Variability.CONTINUOUS; } }