From 5e39f90e9d4665713eba38586b08546f1d581adb Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 2 Feb 2011 13:23:06 -0800 Subject: [PATCH] Resolve build warnings; part 4 Fix unchecked warnings Change-Id: I872740fca4e5050e6ed2922eabc7e46e5e97ff3c --- src/com/android/email/Controller.java | 4 +- src/com/android/email/LegacyConversions.java | 3 +- .../email/activity/AccountShortcutPicker.java | 3 +- .../email/activity/MessageCompose.java | 1 - .../email/mail/internet/MimeMessage.java | 20 ++-- .../android/email/provider/EmailContent.java | 94 +++++++++---------- src/com/android/exchange/ExchangeService.java | 6 +- .../com/android/email/AccountTestCase.java | 4 +- 8 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 2abcde14f..47667b073 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -217,7 +217,9 @@ public class Controller { Mailbox.CONTENT_PROJECTION, WHERE_TYPE_ATTACHMENT, null, null); try { if (c.moveToFirst()) { - return new Mailbox().restore(c); + Mailbox m = new Mailbox(); + m.restore(c); + return m; } } finally { c.close(); diff --git a/src/com/android/email/LegacyConversions.java b/src/com/android/email/LegacyConversions.java index 40d559c6f..4f946dbc1 100644 --- a/src/com/android/email/LegacyConversions.java +++ b/src/com/android/email/LegacyConversions.java @@ -391,7 +391,8 @@ public class LegacyConversions { boolean attachmentFoundInDb = false; try { while (cursor.moveToNext()) { - Attachment dbAttachment = new Attachment().restore(cursor); + Attachment dbAttachment = new Attachment(); + dbAttachment.restore(cursor); // We test each of the fields here (instead of in SQL) because they may be // null, or may be strings. if (stringNotEqual(dbAttachment.mFileName, localAttachment.mFileName)) continue; diff --git a/src/com/android/email/activity/AccountShortcutPicker.java b/src/com/android/email/activity/AccountShortcutPicker.java index d69873995..6dea8a091 100644 --- a/src/com/android/email/activity/AccountShortcutPicker.java +++ b/src/com/android/email/activity/AccountShortcutPicker.java @@ -105,7 +105,8 @@ public class AccountShortcutPicker extends ListActivity public void onItemClick(AdapterView parent, View view, int position, long id) { Cursor cursor = (Cursor)parent.getItemAtPosition(position); - Account account = new Account().restore(cursor); + Account account = new Account(); + account.restore(cursor); setupShortcut(account); finish(); } diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index 65a03c8c7..ea7a834e7 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -601,7 +601,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus /** * Set up address auto-completion adapters. */ - @SuppressWarnings("all") private void setupAddressAdapters() { mAddressAdapterTo = new EmailAddressAdapter(this); mAddressAdapterCc = new EmailAddressAdapter(this); diff --git a/src/com/android/email/mail/internet/MimeMessage.java b/src/com/android/email/mail/internet/MimeMessage.java index ee2ce9717..dfa55b6a5 100644 --- a/src/com/android/email/mail/internet/MimeMessage.java +++ b/src/com/android/email/mail/internet/MimeMessage.java @@ -53,7 +53,7 @@ import java.util.regex.Pattern; public class MimeMessage extends Message { private MimeHeader mHeader; private MimeHeader mExtendedHeader; - + // NOTE: The fields here are transcribed out of headers, and values stored here will supercede // the values found in the headers. Use caution to prevent any out-of-phase errors. In // particular, any adds/changes/deletes here must be echoed by changes in the parse() function. @@ -69,7 +69,7 @@ public class MimeMessage extends Message { // Shared random source for generating local message-id values private static final java.util.Random sRandom = new java.util.Random(); - + // In MIME, en_US-like date format should be used. In other words "MMM" should be encoded to // "Jan", not the other localized format like "Ene" (meaning January in locale es). // This conversion is used when generating outgoing MIME messages. Incoming MIME date @@ -327,7 +327,7 @@ public class MimeMessage extends Message { mReplyTo = replyTo; } } - + /** * Set the mime "Message-ID" header * @param messageId the new Message-ID value @@ -337,7 +337,7 @@ public class MimeMessage extends Message { public void setMessageId(String messageId) throws MessagingException { setHeader("Message-ID", messageId); } - + /** * Get the mime "Message-ID" header. This value will be preloaded with a locally-generated * random ID, if the value has not previously been set. Local generation can be inhibited/ @@ -409,7 +409,7 @@ public class MimeMessage extends Message { /** * Set extended header - * + * * @param name Extended header name * @param value header value - flattened by removing CR-NL if any * remove header if value is null @@ -430,7 +430,7 @@ public class MimeMessage extends Message { /** * Get extended header - * + * * @param name Extended header name * @return header value - null if header does not exist * @throws MessagingException @@ -444,7 +444,7 @@ public class MimeMessage extends Message { /** * Set entire extended headers from String - * + * * @param headers Extended header and its value - "CR-NL-separated pairs * if null or empty, remove entire extended headers * @throws MessagingException @@ -466,7 +466,7 @@ public class MimeMessage extends Message { /** * Get entire extended headers as String - * + * * @return "CR-NL-separated extended headers - null if extended header does not exist */ public String getExtendedHeaders() { @@ -478,7 +478,7 @@ public class MimeMessage extends Message { /** * Write message header and body to output stream - * + * * @param out Output steam to write message header and body. */ public void writeTo(OutputStream out) throws IOException, MessagingException { @@ -500,7 +500,7 @@ public class MimeMessage extends Message { } class MimeMessageBuilder implements ContentHandler { - private Stack stack = new Stack(); + private Stack stack = new Stack(); public MimeMessageBuilder() { } diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 9c3a0de82..1b6f49f77 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -100,7 +100,7 @@ public abstract class EmailContent { // Write the Content into a ContentValues container public abstract ContentValues toContentValues(); // Read the Content from a ContentCursor - public abstract T restore (Cursor cursor); + public abstract void restore (Cursor cursor); // The Uri is lazily initialized public Uri getUri() { @@ -114,13 +114,13 @@ public abstract class EmailContent { return mId != NOT_SAVED; } - @SuppressWarnings("unchecked") // The Content sub class must have a no-arg constructor static public T getContent(Cursor cursor, Class klass) { try { T content = klass.newInstance(); content.mId = cursor.getLong(0); - return (T)content.restore(cursor); + content.restore(cursor); + return content; } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { @@ -382,17 +382,15 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.Body restore(Cursor c) { + public void restore(Cursor cursor) { mBaseUri = EmailContent.Body.CONTENT_URI; - mMessageKey = c.getLong(CONTENT_MESSAGE_KEY_COLUMN); - mHtmlContent = c.getString(CONTENT_HTML_CONTENT_COLUMN); - mTextContent = c.getString(CONTENT_TEXT_CONTENT_COLUMN); - mHtmlReply = c.getString(CONTENT_HTML_REPLY_COLUMN); - mTextReply = c.getString(CONTENT_TEXT_REPLY_COLUMN); - mSourceKey = c.getLong(CONTENT_SOURCE_KEY_COLUMN); - mIntroText = c.getString(CONTENT_INTRO_TEXT_COLUMN); - return this; + mMessageKey = cursor.getLong(CONTENT_MESSAGE_KEY_COLUMN); + mHtmlContent = cursor.getString(CONTENT_HTML_CONTENT_COLUMN); + mTextContent = cursor.getString(CONTENT_TEXT_CONTENT_COLUMN); + mHtmlReply = cursor.getString(CONTENT_HTML_REPLY_COLUMN); + mTextReply = cursor.getString(CONTENT_TEXT_REPLY_COLUMN); + mSourceKey = cursor.getLong(CONTENT_SOURCE_KEY_COLUMN); + mIntroText = cursor.getString(CONTENT_INTRO_TEXT_COLUMN); } public boolean update() { @@ -737,32 +735,30 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.Message restore(Cursor c) { + public void restore(Cursor cursor) { mBaseUri = CONTENT_URI; - mId = c.getLong(CONTENT_ID_COLUMN); - mDisplayName = c.getString(CONTENT_DISPLAY_NAME_COLUMN); - mTimeStamp = c.getLong(CONTENT_TIMESTAMP_COLUMN); - mSubject = c.getString(CONTENT_SUBJECT_COLUMN); - mFlagRead = c.getInt(CONTENT_FLAG_READ_COLUMN) == 1; - mFlagLoaded = c.getInt(CONTENT_FLAG_LOADED_COLUMN); - mFlagFavorite = c.getInt(CONTENT_FLAG_FAVORITE_COLUMN) == 1; - mFlagAttachment = c.getInt(CONTENT_FLAG_ATTACHMENT_COLUMN) == 1; - mFlags = c.getInt(CONTENT_FLAGS_COLUMN); - mServerId = c.getString(CONTENT_SERVER_ID_COLUMN); - mServerTimeStamp = c.getLong(CONTENT_SERVER_TIMESTAMP_COLUMN); - mClientId = c.getString(CONTENT_CLIENT_ID_COLUMN); - mMessageId = c.getString(CONTENT_MESSAGE_ID_COLUMN); - mMailboxKey = c.getLong(CONTENT_MAILBOX_KEY_COLUMN); - mAccountKey = c.getLong(CONTENT_ACCOUNT_KEY_COLUMN); - mFrom = c.getString(CONTENT_FROM_LIST_COLUMN); - mTo = c.getString(CONTENT_TO_LIST_COLUMN); - mCc = c.getString(CONTENT_CC_LIST_COLUMN); - mBcc = c.getString(CONTENT_BCC_LIST_COLUMN); - mReplyTo = c.getString(CONTENT_REPLY_TO_COLUMN); - mMeetingInfo = c.getString(CONTENT_MEETING_INFO_COLUMN); - mSnippet = c.getString(CONTENT_SNIPPET_COLUMN); - return this; + mId = cursor.getLong(CONTENT_ID_COLUMN); + mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN); + mTimeStamp = cursor.getLong(CONTENT_TIMESTAMP_COLUMN); + mSubject = cursor.getString(CONTENT_SUBJECT_COLUMN); + mFlagRead = cursor.getInt(CONTENT_FLAG_READ_COLUMN) == 1; + mFlagLoaded = cursor.getInt(CONTENT_FLAG_LOADED_COLUMN); + mFlagFavorite = cursor.getInt(CONTENT_FLAG_FAVORITE_COLUMN) == 1; + mFlagAttachment = cursor.getInt(CONTENT_FLAG_ATTACHMENT_COLUMN) == 1; + mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN); + mServerId = cursor.getString(CONTENT_SERVER_ID_COLUMN); + mServerTimeStamp = cursor.getLong(CONTENT_SERVER_TIMESTAMP_COLUMN); + mClientId = cursor.getString(CONTENT_CLIENT_ID_COLUMN); + mMessageId = cursor.getString(CONTENT_MESSAGE_ID_COLUMN); + mMailboxKey = cursor.getLong(CONTENT_MAILBOX_KEY_COLUMN); + mAccountKey = cursor.getLong(CONTENT_ACCOUNT_KEY_COLUMN); + mFrom = cursor.getString(CONTENT_FROM_LIST_COLUMN); + mTo = cursor.getString(CONTENT_TO_LIST_COLUMN); + mCc = cursor.getString(CONTENT_CC_LIST_COLUMN); + mBcc = cursor.getString(CONTENT_BCC_LIST_COLUMN); + mReplyTo = cursor.getString(CONTENT_REPLY_TO_COLUMN); + mMeetingInfo = cursor.getString(CONTENT_MEETING_INFO_COLUMN); + mSnippet = cursor.getString(CONTENT_SNIPPET_COLUMN); } public boolean update() { @@ -1133,8 +1129,7 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.Account restore(Cursor cursor) { + public void restore(Cursor cursor) { mId = cursor.getLong(CONTENT_ID_COLUMN); mBaseUri = CONTENT_URI; mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN); @@ -1154,7 +1149,6 @@ public abstract class EmailContent { mSecurityFlags = cursor.getLong(CONTENT_SECURITY_FLAGS_COLUMN); mSecuritySyncKey = cursor.getString(CONTENT_SECURITY_SYNC_KEY_COLUMN); mSignature = cursor.getString(CONTENT_SIGNATURE_COLUMN); - return this; } private long getId(Uri u) { @@ -2019,7 +2013,9 @@ public abstract class EmailContent { Attachment[] attachments = new Attachment[count]; for (int i = 0; i < count; ++i) { c.moveToNext(); - attachments[i] = new Attachment().restore(c); + Attachment attach = new Attachment(); + attach.restore(c); + attachments[i] = attach; } return attachments; } finally { @@ -2061,8 +2057,7 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.Attachment restore(Cursor cursor) { + public void restore(Cursor cursor) { mBaseUri = CONTENT_URI; mId = cursor.getLong(CONTENT_ID_COLUMN); mFileName= cursor.getString(CONTENT_FILENAME_COLUMN); @@ -2077,7 +2072,6 @@ public abstract class EmailContent { mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN); mContentBytes = cursor.getBlob(CONTENT_CONTENT_BYTES_COLUMN); mAccountKey = cursor.getLong(CONTENT_ACCOUNT_KEY_COLUMN); - return this; } @Override @@ -2361,7 +2355,7 @@ public abstract class EmailContent { try { if (c.moveToFirst()) { - return EmailContent.getContent(c, Mailbox.class); + return getContent(c, Mailbox.class); } else { return null; } @@ -2371,8 +2365,7 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.Mailbox restore(Cursor cursor) { + public void restore(Cursor cursor) { mBaseUri = CONTENT_URI; mId = cursor.getLong(CONTENT_ID_COLUMN); mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN); @@ -2389,7 +2382,6 @@ public abstract class EmailContent { mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN); mVisibleLimit = cursor.getInt(CONTENT_VISIBLE_LIMIT_COLUMN); mSyncStatus = cursor.getString(CONTENT_SYNC_STATUS_COLUMN); - return this; } @Override @@ -2634,8 +2626,7 @@ public abstract class EmailContent { } @Override - @SuppressWarnings("unchecked") - public EmailContent.HostAuth restore(Cursor cursor) { + public void restore(Cursor cursor) { mBaseUri = CONTENT_URI; mId = cursor.getLong(CONTENT_ID_COLUMN); mProtocol = cursor.getString(CONTENT_PROTOCOL_COLUMN); @@ -2646,7 +2637,6 @@ public abstract class EmailContent { mPassword = cursor.getString(CONTENT_PASSWORD_COLUMN); mDomain = cursor.getString(CONTENT_DOMAIN_COLUMN); mAccountKey = cursor.getLong(CONTENT_ACCOUNT_KEY_COLUMN); - return this; } @Override diff --git a/src/com/android/exchange/ExchangeService.java b/src/com/android/exchange/ExchangeService.java index 8a82f812e..0f0df3693 100644 --- a/src/com/android/exchange/ExchangeService.java +++ b/src/com/android/exchange/ExchangeService.java @@ -473,7 +473,8 @@ public class ExchangeService extends Service implements Runnable { if (hostAuthId > 0) { HostAuth ha = HostAuth.restoreHostAuthWithId(context, hostAuthId); if (ha != null && ha.mProtocol.equals("eas")) { - Account account = new Account().restore(c); + Account account = new Account(); + account.restore(c); // Cache the HostAuth account.mHostAuthRecv = ha; accounts.add(account); @@ -1228,7 +1229,8 @@ public class ExchangeService extends Service implements Runnable { try { if (c.moveToFirst()) { synchronized(sSyncLock) { - Mailbox m = new Mailbox().restore(c); + Mailbox m = new Mailbox(); + m.restore(c); Account acct = Account.restoreAccountWithId(context, accountId); if (acct == null) { reloadFolderListFailed(accountId); diff --git a/tests/src/com/android/email/AccountTestCase.java b/tests/src/com/android/email/AccountTestCase.java index 5c8783a1a..229fb7560 100644 --- a/tests/src/com/android/email/AccountTestCase.java +++ b/tests/src/com/android/email/AccountTestCase.java @@ -70,7 +70,9 @@ public abstract class AccountTestCase extends ProviderTestCase2 { Account.CONTENT_PROJECTION, null, null, null); try { while (c.moveToNext()) { - accountList.add(new Account().restore(c)); + Account account = new Account(); + account.restore(c); + accountList.add(account); } } finally { c.close();