Merge pull request #686 from k9mail/art/more-static-analysis-fixes

Fix static analysis warnings and stop using nulls everywhere
This commit is contained in:
cketti 2015-07-16 08:39:34 +02:00
commit 9050ef16a2
9 changed files with 28 additions and 27 deletions

View File

@ -22,6 +22,9 @@ public interface Part {
String getContentId(); String getContentId();
/**
* Returns an array of headers of the given name. The array may be empty.
*/
String[] getHeader(String name) throws MessagingException; String[] getHeader(String name) throws MessagingException;
boolean isMimeType(String mimeType) throws MessagingException; boolean isMimeType(String mimeType) throws MessagingException;

View File

@ -49,8 +49,8 @@ class JisSupport {
private static String getJisVariantFromMailerHeaders(Message message) throws MessagingException { private static String getJisVariantFromMailerHeaders(Message message) throws MessagingException {
String mailerHeaders[] = message.getHeader("X-Mailer"); String[] mailerHeaders = message.getHeader("X-Mailer");
if (mailerHeaders == null || mailerHeaders.length == 0) if (mailerHeaders.length == 0)
return null; return null;
if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail ")) if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail "))
@ -61,8 +61,8 @@ class JisSupport {
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException { private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
String receivedHeaders[] = message.getHeader("Received"); String[] receivedHeaders = message.getHeader("Received");
if (receivedHeaders == null) if (receivedHeaders.length == 0)
return null; return null;
for (String receivedHeader : receivedHeaders) { for (String receivedHeader : receivedHeaders) {

View File

@ -26,7 +26,7 @@ public class MimeHeader {
public String getFirstHeader(String name) { public String getFirstHeader(String name) {
String[] header = getHeader(name); String[] header = getHeader(name);
if (header == null) { if (header.length == 0) {
return null; return null;
} }
return header[0]; return header[0];
@ -65,9 +65,6 @@ public class MimeHeader {
values.add(field.getValue()); values.add(field.getValue());
} }
} }
if (values.isEmpty()) {
return null;
}
return values.toArray(EMPTY_STRING_ARRAY); return values.toArray(EMPTY_STRING_ARRAY);
} }

View File

@ -1937,7 +1937,7 @@ public class ImapStore extends RemoteStore {
*/ */
String[] messageIdHeader = message.getHeader("Message-ID"); String[] messageIdHeader = message.getHeader("Message-ID");
if (messageIdHeader == null || messageIdHeader.length == 0) { if (messageIdHeader.length == 0) {
if (K9MailLib.isDebug()) if (K9MailLib.isDebug())
Log.d(LOG_TAG, "Did not get a message-id in order to search for UID for " + getLogId()); Log.d(LOG_TAG, "Did not get a message-id in order to search for UID for " + getLogId());
return null; return null;

View File

@ -2362,13 +2362,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// Read In-Reply-To header from draft // Read In-Reply-To header from draft
final String[] inReplyTo = message.getHeader("In-Reply-To"); final String[] inReplyTo = message.getHeader("In-Reply-To");
if ((inReplyTo != null) && (inReplyTo.length >= 1)) { if (inReplyTo.length >= 1) {
mInReplyTo = inReplyTo[0]; mInReplyTo = inReplyTo[0];
} }
// Read References header from draft // Read References header from draft
final String[] references = message.getHeader("References"); final String[] references = message.getHeader("References");
if ((references != null) && (references.length >= 1)) { if (references.length >= 1) {
mReferences = references[0]; mReferences = references[0];
} }
@ -2379,8 +2379,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// Decode the identity header when loading a draft. // Decode the identity header when loading a draft.
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob. // See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
Map<IdentityField, String> k9identity = new HashMap<IdentityField, String>(); Map<IdentityField, String> k9identity = new HashMap<IdentityField, String>();
if (message.getHeader(K9.IDENTITY_HEADER) != null && message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null) { String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
k9identity = IdentityHeaderParser.parse(message.getHeader(K9.IDENTITY_HEADER)[0]);
if (identityHeaders.length > 0 && identityHeaders[0] != null) {
k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
} }
Identity newIdentity = new Identity(); Identity newIdentity = new Identity();

View File

@ -3425,7 +3425,7 @@ public class MessagingController implements Runnable {
try { try {
if (message.getHeader(K9.IDENTITY_HEADER) != null) { if (message.getHeader(K9.IDENTITY_HEADER).length > 0) {
Log.v(K9.LOG_TAG, "The user has set the Outbox and Drafts folder to the same thing. " + Log.v(K9.LOG_TAG, "The user has set the Outbox and Drafts folder to the same thing. " +
"This message appears to be a draft, so K-9 will not send it"); "This message appears to be a draft, so K-9 will not send it");
continue; continue;

View File

@ -1457,7 +1457,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
private String getTransferEncoding(Part part) throws MessagingException { private String getTransferEncoding(Part part) throws MessagingException {
String[] contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING); String[] contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING);
if (contentTransferEncoding != null && contentTransferEncoding.length > 0) { if (contentTransferEncoding.length > 0) {
return contentTransferEncoding[0].toLowerCase(Locale.US); return contentTransferEncoding[0].toLowerCase(Locale.US);
} }
@ -1821,14 +1821,14 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
// Get the message IDs from the "References" header line // Get the message IDs from the "References" header line
String[] referencesArray = message.getHeader("References"); String[] referencesArray = message.getHeader("References");
List<String> messageIds = null; List<String> messageIds = null;
if (referencesArray != null && referencesArray.length > 0) { if (referencesArray.length > 0) {
messageIds = Utility.extractMessageIds(referencesArray[0]); messageIds = Utility.extractMessageIds(referencesArray[0]);
} }
// Append the first message ID from the "In-Reply-To" header line // Append the first message ID from the "In-Reply-To" header line
String[] inReplyToArray = message.getHeader("In-Reply-To"); String[] inReplyToArray = message.getHeader("In-Reply-To");
String inReplyTo; String inReplyTo;
if (inReplyToArray != null && inReplyToArray.length > 0) { if (inReplyToArray.length > 0) {
inReplyTo = Utility.extractMessageId(inReplyToArray[0]); inReplyTo = Utility.extractMessageId(inReplyToArray[0]);
if (inReplyTo != null) { if (inReplyTo != null) {
if (messageIds == null) { if (messageIds == null) {

View File

@ -560,7 +560,7 @@ public class LocalMessageExtractor {
// attachments. // attachments.
if (contentDisposition != null && if (contentDisposition != null &&
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") && MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") &&
part.getHeader(MimeHeader.HEADER_CONTENT_ID) != null) { part.getHeader(MimeHeader.HEADER_CONTENT_ID).length > 0) {
firstClassAttachment = false; firstClassAttachment = false;
} }

View File

@ -1022,15 +1022,10 @@ public class MessageProvider extends ContentProvider {
// Note: can only delete a message // Note: can only delete a message
List<String> segments = null; List<String> segments = uri.getPathSegments();
int accountId = -1; int accountId = Integer.parseInt(segments.get(1));
String folderName = null; String folderName = segments.get(2);
String msgUid = null; String msgUid = segments.get(3);
segments = uri.getPathSegments();
accountId = Integer.parseInt(segments.get(1));
folderName = segments.get(2);
msgUid = segments.get(3);
// get account // get account
Account myAccount = null; Account myAccount = null;
@ -1044,6 +1039,10 @@ public class MessageProvider extends ContentProvider {
} }
} }
if (myAccount == null) {
Log.e(K9.LOG_TAG, "Could not find account with id " + accountId);
}
// get localstore parameter // get localstore parameter
LocalMessage msg = null; LocalMessage msg = null;
try { try {