voodoodyne / subethasmtp

SubEtha SMTP is a Java library for receiving SMTP mail
Other
349 stars 139 forks source link

ConcurrentModificationException thrown when using Wiser #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Wiser class does not correctly synchronize access to its messages property, 
resulting in ConcurrentModificationException.

This problem occurs in our automated multi-threaded acceptance tests which use 
Wiser. However this problem can be demonstrated in a single thread by adding 
this test to MessageContentTest. 

  public void testDoesNotThrowConcurrentModificationException() throws Exception
    {
        MimeMessage message = new MimeMessage(this.session);
        message.addRecipient(Message.RecipientType.TO, new InternetAddress("anyone@anywhere.com"));
        message.setFrom(new InternetAddress("someone@somewhereelse.com"));
        Transport.send(message);
        List<WiserMessage> messages = this.wiser.getMessages();
        Iterator<WiserMessage> iterator = messages.iterator();
        Transport.send(message);
        iterator.next();
        assertEquals(2, this.wiser.getMessages().size());
    }

The simplest fix would be to change the property declaration in Wiser.java to 
    List<WiserMessage> messages = new CopyOnWriteArrayList<WiserMessage>();

Original issue reported on code.google.com by s_etheri...@hotmail.com on 19 Dec 2010 at 10:26

GoogleCodeExporter commented 9 years ago
see also issue 38

Original comment by s_etheri...@hotmail.com on 19 Dec 2010 at 10:35

GoogleCodeExporter commented 9 years ago

Original comment by lhori...@gmail.com on 24 Dec 2010 at 9:21

GoogleCodeExporter commented 9 years ago
Wiser.messages has been changed to 'protected' so that you can extend Wiser and 
change the implementation to anything you wish.

Original comment by lhori...@gmail.com on 24 Dec 2010 at 9:29