| 
25 | 25 | import java.util.Properties;  | 
26 | 26 | import java.util.concurrent.CountDownLatch;  | 
27 | 27 | import java.util.concurrent.TimeUnit;  | 
 | 28 | +import java.util.concurrent.atomic.AtomicBoolean;  | 
28 | 29 | import java.util.concurrent.atomic.AtomicInteger;  | 
29 | 30 | import java.util.concurrent.atomic.AtomicReference;  | 
30 | 31 | import java.util.logging.Handler;  | 
@@ -995,7 +996,7 @@ public void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Excep  | 
995 | 996 | 		AbstractMailReceiver receiver = new ImapMailReceiver();  | 
996 | 997 | 		MimeMessage msg1 = GreenMailUtil.newMimeMessage("test1");  | 
997 | 998 | 		MimeMessage greenMailMsg2 = GreenMailUtil.newMimeMessage("test2");  | 
998 |  | -		TestThrowingMimeMessage msg2 = new TestThrowingMimeMessage(greenMailMsg2, 1);  | 
 | 999 | +		TestThrowingMimeMessage msg2 = new TestThrowingMimeMessage(greenMailMsg2);  | 
999 | 1000 | 		receiver = receiveAndMarkAsReadDontDeleteGuts(receiver, msg1, msg2, false);  | 
1000 | 1001 | 		assertThatThrownBy(receiver::receive)  | 
1001 | 1002 | 				.isInstanceOf(MessagingException.class)  | 
@@ -1051,18 +1052,17 @@ public void close() throws SecurityException {  | 
1051 | 1052 | 
 
  | 
1052 | 1053 | 	private static class TestThrowingMimeMessage extends MimeMessage {  | 
1053 | 1054 | 
 
  | 
1054 |  | -		protected final AtomicInteger exceptionsBeforeWrite;  | 
 | 1055 | +		protected final AtomicBoolean throwExceptionBeforeWrite = new AtomicBoolean(true);  | 
1055 | 1056 | 
 
  | 
1056 | 1057 | 		protected final Flags myTestFlags = new Flags();  | 
1057 | 1058 | 
 
  | 
1058 |  | -		private TestThrowingMimeMessage(MimeMessage source, int exceptionsBeforeWrite) throws MessagingException {  | 
 | 1059 | +		private TestThrowingMimeMessage(MimeMessage source) throws MessagingException {  | 
1059 | 1060 | 			super(source);  | 
1060 |  | -			this.exceptionsBeforeWrite = new AtomicInteger(exceptionsBeforeWrite);  | 
1061 | 1061 | 		}  | 
1062 | 1062 | 
 
  | 
1063 | 1063 | 		@Override  | 
1064 | 1064 | 		public void writeTo(OutputStream os) throws IOException, MessagingException {  | 
1065 |  | -			if (this.exceptionsBeforeWrite.decrementAndGet() >= 0) {  | 
 | 1065 | +			if (this.throwExceptionBeforeWrite.getAndSet(false)) {  | 
1066 | 1066 | 				throw new IOException("Simulated exception");  | 
1067 | 1067 | 			}  | 
1068 | 1068 | 			super.writeTo(os);  | 
 | 
0 commit comments