From 9134419990291e2111cafdae19aaf679fabafefc Mon Sep 17 00:00:00 2001 From: jkauttio Date: Wed, 13 Jan 2016 13:46:51 +0000 Subject: [PATCH] Fix a resource name read after the resource is removed refs #6254 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@32258 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/manager/SysdynExperiments.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java index aa9744ee..94c1d5f5 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java @@ -402,13 +402,17 @@ public class SysdynExperiments { public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException { graph.markUndoPoint(); - Resource model = Variables.getModel(graph, input); - Resource child = Layer0Utils.getPossibleChild(graph, model, name); - SysdynResource SYSDYN = SysdynResource.getInstance(graph); - - if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition)) - RemoverUtil.remove(graph, child); - Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + graph.getRelatedValue2(child, Layer0.getInstance(graph).HasName, Bindings.STRING)); + Resource model = Variables.getModel(graph, input); + Resource child = Layer0Utils.getPossibleChild(graph, model, name); + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource SYSDYN = SysdynResource.getInstance(graph); + + if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition)) { + // is it really necessary to fetch the name from the graph and not just use the provided name? + String actualName = graph.getRelatedValue2(child, L0.HasName, Bindings.STRING); + RemoverUtil.remove(graph, child); + Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + actualName); + } } } -- 2.47.1