次のコードで ConcurrentModificationException を取得します
コードを実行するとうまくいきましたが、突然例外がスローされました。リストの変更が原因だと思いますが、修正方法がわかりません
if (myRulesIncr!=null)
{
Iterator itReceivedRules = myRulesIncr.iterator();
while (itReceivedRules.hasNext())
{
RuleModel currentReceived = (RuleModel) itReceivedRules.next();
if (receivedRulesExisting!=null)
{
Iterator itReceivedRulesExisting = receivedRulesExisting.iterator();
while (itReceivedRulesExisting.hasNext())
{
RuleModel currentExisting = (RuleModel) itReceivedRulesExisting.next();
if(currentExisting.getRuleId().equals(currentReceived.getRuleId()))
{
//TODO:replace the rule else add it.
if(currentReceived.getStatus()!="D")
{
//replace the existing rule with the new one
receivedRulesExisting.remove(currentExisting);
receivedRulesExisting.add(currentReceived);
}
else
{
receivedRulesExisting.remove(currentExisting);
}
}
else
{
//Add the new rule to the existing rules
receivedRulesExisting.add(currentReceived);
}
}
}
}
}
これで私を助けてください。