Skip to content

Commit ae687cd

Browse files
committed
improve OcppJsonChargePoint impl
1 parent 297d494 commit ae687cd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/test/java/de/rwth/idsg/steve/utils/OcppJsonChargePoint.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import java.io.IOException;
3030
import java.net.URI;
31-
import java.util.Collection;
31+
import java.util.ArrayList;
3232
import java.util.LinkedHashMap;
3333
import java.util.Map;
3434
import java.util.UUID;
@@ -129,7 +129,10 @@ public <T extends ResponseType> void prepare(RequestType request, Class<T> respo
129129
}
130130

131131
public void process() {
132-
Collection<ResponseContext> values = responseContextMap.values();
132+
// copy the values in a new list to be iterated over, because otherwise we get a ConcurrentModificationException,
133+
// since the onMessage(..) uses the same responseContextMap to remove an item while looping over its items here.
134+
ArrayList<ResponseContext> values = new ArrayList<>(responseContextMap.values());
135+
133136
receivedResponsesSignal = new CountDownLatch(values.size());
134137

135138
// send all messages
@@ -147,9 +150,6 @@ public void process() {
147150
} catch (InterruptedException e) {
148151
throw new RuntimeException(e);
149152
}
150-
151-
// we processed everything in the map, clear it such that the map is empty for the next process call
152-
responseContextMap.clear();
153153
}
154154

155155
public void close() {

0 commit comments

Comments
 (0)