From 2894b5b157277bd2aa550014e8aad230bc6d66c1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 10 Mar 2014 22:33:22 +0100 Subject: [PATCH] [Bugfix] Fixed two bugs in CachedElementMap First bug was a situation where the update() method returned a list of null elements due to removing and then trying to "replace" the existing element. Then fixed a bug where when an element was removed its ID was not removed the key set. --- src/main/java/li/strolch/agent/impl/CachedElementMap.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/agent/impl/CachedElementMap.java b/src/main/java/li/strolch/agent/impl/CachedElementMap.java index ab1e8b875..fee93197b 100644 --- a/src/main/java/li/strolch/agent/impl/CachedElementMap.java +++ b/src/main/java/li/strolch/agent/impl/CachedElementMap.java @@ -305,11 +305,13 @@ public abstract class CachedElementMap implements Elem synchronized (byType) { for (T element : list) { - if (byType.remove(element.getId()) == null) { + T replacedElement = byType.remove(element.getId()); + if (replacedElement == null) { msg = MessageFormat.format(msg, element.getLocator()); throw new StrolchPersistenceException(msg); } - replacedElements.add(byType.put(element.getId(), element)); + byType.put(element.getId(), element); + replacedElements.add(replacedElement); } } } @@ -350,6 +352,7 @@ public abstract class CachedElementMap implements Elem msg = MessageFormat.format(msg, element.getLocator()); throw new StrolchPersistenceException(msg); } + this.allKeys.remove(element.getId()); if (byType.isEmpty()) { synchronized (this.elementMap) {