It is due to thread lock on an Object. You can try and break your code into pieces. First try and get all the rules in a list that matches your criteria. Call this a refinedRuleList, then iterate thru this refinedRuleList for Expressions and remove. Give this a try!  Thanks, #AJ Aslam
I have modified most of our rules across several FMSs and use a number of Rule Level Variables. I manage these variables through groovy scripts. Recently, I needed to modify a variable that appears in all the rules.  This is the script I've written so far:  import com.quest.nitro.service.sl.interfaces.rule.*; def ruleInfo = "";def ruleSvc = server.get("RuleService");def ruleList = ["DBSS - ADH Service Status"];def varExp = "INST_NAME";def varText = "scope.parent_node.mon_instance_name"; allRules = ruleSvc.getAllRules(); for (rule in allRules){    def ruleName = rule.getName();   //def ruleCart = rule.getCartridgeName();    if (ruleList.contains(ruleName))   //if (ruleCart.equals("DB_SQL_Server_UI"))   {       def ExpressionSet = rule.getExpressions();      for (expression in ExpressionSet)      {          if (expression.getName().equals("INST_NAME")){             ExpressionSet.remove(expression);            ruleInfo += "Removed $varExp variable from $ruleName \n";         }       }      //add the new expression      ExpressionSet.add(rule.createExpression("INST_NAME", varText));       rule.setExpressions(ExpressionSet);      ruleSvc.saveRule(rule);      ruleInfo += "Added $varExp variable to $ruleName \n";   }} return ruleInfo;   The portion of the script that adds the variable work consistantly.  The portion of the script the removes the rule level expresion fails most of the time with the following error:   com.quest.nitro.service.sl.interfaces.scripting.ScriptAbortException: script1001968: java.util.ConcurrentModificationException  I am still rather new to groovy and java scripting but I gather that when I iterate over a collection which is being modified in another thread, the Iterator throws a java.util.ConcurrentModificationException.  I read that I should be looking at synchronizing the collection in some way.  Before I go down that rabit hole I thought I would simply ask here, How should I be writing this code so it will work consistantly?
Foglight v558 - Script fails with ScriptAbortException: script1001968: 
java.util.ConcurrentModificationException