ConcurrentModificationException
flozano opened this issue · comments
The list of messages in Wiser
is declared as:
private final List<WiserMessage> messages = Collections
.synchronizedList(new ArrayList<WiserMessage>());
but if you try to directly iterate over the result of getMessages()
while messages are being received, you get:
Caused by: java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1042)
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:996)
at com.mycompany.common.email.MockSmtpServer.getMessages(MockSmtpServer.java:75)
Relevant parts of MockSmtpServer:
private Wiser simpleSmtpServer;
Line 75:
for (WiserMessage message : simpleSmtpServer.getMessages()) {
It's really inconvenient to have to synchronize on the list to retrieve any operation, it'd be nicer if the messages was just declared as:
private final List<WiserMessage> messages = new CopyOnWriteArrayList<WiserMessage>();
Proposed fix:
#23
#23 has been merged