This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new c58f0d7  [SpotBugs] Fix concurrent counting of chunks in 
IMAPExportMbox.
c58f0d7 is described below

commit c58f0d760fe9b93f0c5acabbb6baad0874908ff7
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Feb 12 10:55:55 2021 -0500

    [SpotBugs] Fix concurrent counting of chunks in IMAPExportMbox.
---
 src/changes/changes.xml                                      | 12 ++++++++----
 .../org/apache/commons/net/examples/mail/IMAPExportMbox.java |  7 ++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7bf30c1..e9870d8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,18 +65,22 @@ The <action> type attribute can be add,update,fix,remove.
     <body>
         <release version="3.8.0" date="2020-MM-DD" description="Maintenance 
and bug fix release (Java 7).">
             <!-- ADD -->
-           <action type="update" dev="ggregory" due-to="Arturo Bernal, Gary 
Gregory">
+           <action type="add" dev="ggregory" due-to="Arturo Bernal, Gary 
Gregory">
             Add and use NetConstants.
             </action>
-           <action type="update" dev="ggregory" due-to="Gary Gregory">
+           <action type="add" dev="ggregory" due-to="Gary Gregory">
             Add and use SocketClient.applySocketAttributes().
             </action>
-            <action type="update" dev="ggregory" due-to="Gary Gregory">
+            <action type="add" dev="ggregory" due-to="Gary Gregory">
             Add FTPClient.hasFeature(FTPCmd).
             </action>
-            <action type="update" dev="ggregory" due-to="Gary Gregory">
+            <action type="add" dev="ggregory" due-to="Gary Gregory">
             Add FTPClient.mdtmCalendar(String).
             </action>
+            <!--  FIX -->
+            <action type="fox" dev="ggregory" due-to="Gary Gregory">
+            Fix concurrent counting of chunks in IMAPExportMbox.
+            </action>
             <!-- UPDATE -->
             <action type="update" dev="ggregory" due-to="Dependabot">
             Bump actions/checkout from v2.3.3 to v2.3.4 #69.
diff --git 
a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java 
b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
index 19257be..54f5f15 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
@@ -30,6 +30,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -276,7 +277,7 @@ public final class IMAPExportMbox
             }
 
         } catch (final IOException ioe) {
-            final String count = mboxListener == null ? "?" : 
Integer.toString(mboxListener.total);
+            final String count = mboxListener == null ? "?" : 
mboxListener.total.toString();
             System.err.println(
                     "FETCH " + sequenceSet + " " + itemNames + " failed after 
processing " + count + " complete messages ");
             if (mboxListener != null) {
@@ -331,7 +332,7 @@ public final class IMAPExportMbox
     private static class MboxListener implements IMAPChunkListener {
 
         private final BufferedWriter bufferedWriter;
-        volatile int total;
+        volatile AtomicInteger total = new AtomicInteger();
         volatile String lastFetched;
         volatile List<String> missingIds = new ArrayList<>();
         volatile long lastSeq = -1;
@@ -424,7 +425,7 @@ public final class IMAPExportMbox
                 throw new RuntimeException(e); // chunkReceived cannot throw a 
checked Exception
             }
             lastFetched = firstLine;
-            total++;
+            total.incrementAndGet();
             if (checkSequence) {
                 m = PATSEQ.matcher(firstLine);
                 if (m.lookingAt()) { // found a match

Reply via email to