1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-02-07 02:30:10 -05:00

Fixes Issue 1664

Correct thread safety on some member variables when doing null checks.

Explicitly check for mMessageCount == -1 and stop=true in idling loop.

However, the original error message "Message count = -1 for folder"
will still arise in some circumstances and is a valid error to
report.
This commit is contained in:
Daniel Applebaum 2010-07-03 15:22:54 +00:00
parent 318099082f
commit cdbcb188ec

View File

@ -2509,7 +2509,11 @@ public class ImapStore extends Store
protected void setReadTimeout(int millis) throws SocketException protected void setReadTimeout(int millis) throws SocketException
{ {
mSocket.setSoTimeout(millis); Socket sock = mSocket;
if (sock != null)
{
sock.setSoTimeout(millis);
}
} }
protected boolean isIdleCapable() protected boolean isIdleCapable()
@ -2840,17 +2844,23 @@ public class ImapStore extends Store
{ {
if (doneSent.compareAndSet(false, true) == true) if (doneSent.compareAndSet(false, true) == true)
{ {
mConnection.setReadTimeout(Store.SOCKET_READ_TIMEOUT); ImapConnection conn = mConnection;
sendContinuation("DONE"); if (conn != null)
{
conn.setReadTimeout(Store.SOCKET_READ_TIMEOUT);
sendContinuation("DONE");
}
} }
} }
private void sendContinuation(String continuation) private void sendContinuation(String continuation)
throws MessagingException, IOException throws MessagingException, IOException
{ {
if (mConnection != null) ImapConnection conn = mConnection;
if (conn != null)
{ {
mConnection.sendContinuation(continuation); conn.sendContinuation(continuation);
} }
} }
@ -2883,24 +2893,29 @@ public class ImapStore extends Store
} }
ImapConnection oldConnection = mConnection; ImapConnection oldConnection = mConnection;
internalOpen(OpenMode.READ_ONLY); internalOpen(OpenMode.READ_ONLY);
if (mConnection == null) ImapConnection conn = mConnection;
if (conn == null)
{ {
receiver.pushError("Could not establish connection for IDLE", null); receiver.pushError("Could not establish connection for IDLE", null);
throw new MessagingException("Could not establish connection for IDLE"); throw new MessagingException("Could not establish connection for IDLE");
} }
if (mConnection.isIdleCapable() == false) if (conn.isIdleCapable() == false)
{ {
stop.set(true); stop.set(true);
receiver.pushError("IMAP server is not IDLE capable: " + mConnection.toString(), null); receiver.pushError("IMAP server is not IDLE capable: " + conn.toString(), null);
throw new MessagingException("IMAP server is not IDLE capable:" + mConnection.toString()); throw new MessagingException("IMAP server is not IDLE capable:" + conn.toString());
} }
if (mAccount.isPushPollOnConnect() && (mConnection != oldConnection || needsPoll.getAndSet(false) == true)) if (stop.get() != true && mAccount.isPushPollOnConnect() && (conn != oldConnection || needsPoll.getAndSet(false) == true))
{ {
List<ImapResponse> untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses); List<ImapResponse> untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses);
storedUntaggedResponses.clear(); storedUntaggedResponses.clear();
processUntaggedResponses(untaggedResponses); processUntaggedResponses(untaggedResponses);
if (mMessageCount == -1)
{
throw new MessagingException("Message count = -1 for idling");
}
receiver.syncFolder(ImapFolderPusher.this); receiver.syncFolder(ImapFolderPusher.this);
} }
if (stop.get() == true) if (stop.get() == true)
@ -2972,11 +2987,12 @@ public class ImapStore extends Store
receiver.setPushActive(getName(), true); receiver.setPushActive(getName(), true);
idling.set(true); idling.set(true);
doneSent.set(false); doneSent.set(false);
if (mConnection == null)
{ if (conn == null)
throw new MessagingException("No connection available for idling"); {
} throw new MessagingException("No connection available for idling");
mConnection.setReadTimeout((getAccount().getIdleRefreshMinutes() * 60 * 1000) + IDLE_READ_TIMEOUT_INCREMENT); }
conn.setReadTimeout((getAccount().getIdleRefreshMinutes() * 60 * 1000) + IDLE_READ_TIMEOUT_INCREMENT);
untaggedResponses = executeSimpleCommand(COMMAND_IDLE, false, ImapFolderPusher.this); untaggedResponses = executeSimpleCommand(COMMAND_IDLE, false, ImapFolderPusher.this);
idling.set(false); idling.set(false);
delayTime.set(NORMAL_DELAY_TIME); delayTime.set(NORMAL_DELAY_TIME);
@ -3335,11 +3351,12 @@ public class ImapStore extends Store
{ {
listeningThread.interrupt(); listeningThread.interrupt();
} }
if (mConnection != null) ImapConnection conn = mConnection;
if (conn != null)
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Closing mConnection to stop pushing for " + getLogId()); Log.v(K9.LOG_TAG, "Closing mConnection to stop pushing for " + getLogId());
mConnection.close(); conn.close();
} }
else else
{ {