From fc98deba6d7be8daca820d315d2e265c57dca36f Mon Sep 17 00:00:00 2001 From: Piotr Wielgolaski Date: Wed, 15 Jan 2020 12:33:10 +0100 Subject: [PATCH] fix: fix ConcurrentModificationException it was reported in com.tomtom.james.newagent.JamesHQ.prapareObjectiveForSignleInformationPoint(JamesHQ.java:107) --- .../james/newagent/tools/BasicClassStructure.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/james-agent/src/main/java/com/tomtom/james/newagent/tools/BasicClassStructure.java b/james-agent/src/main/java/com/tomtom/james/newagent/tools/BasicClassStructure.java index ccea56c..04dc7b7 100644 --- a/james-agent/src/main/java/com/tomtom/james/newagent/tools/BasicClassStructure.java +++ b/james-agent/src/main/java/com/tomtom/james/newagent/tools/BasicClassStructure.java @@ -14,16 +14,13 @@ public boolean contains(String className) { @Override public Set getChildren(String className) { - return (container.get(className) != null) ? container.get(className) : new HashSet<>(); + return (container.get(className) != null) ? new HashSet<>(container.get(className) ): new HashSet<>(); } - // FIXME - if you want to implement multithreaded classScanner there is the point that multithreading pitfall is waiting for you - it's not threadsafe !!!!! @Override - public void addChild(String className, Class clazz) { - container.computeIfAbsent(className, key -> new HashSet<>()); - Set classSet = container.get(className); - classSet.add(clazz); - container.put(className, classSet); + public synchronized void addChild(String className, Class clazz) { + container.computeIfAbsent(className, key -> new HashSet<>()) + .add(clazz); } @Override