1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 03:32:16 -05:00

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

static analysis fixes
This commit is contained in:
cketti 2015-06-17 21:51:11 +02:00
commit ee7a95b750
6 changed files with 60 additions and 60 deletions

View File

@ -46,24 +46,26 @@ public class BinaryTempFileBody implements RawDataBody, SizeAware {
try { try {
File newFile = File.createTempFile("body", null, mTempDirectory); File newFile = File.createTempFile("body", null, mTempDirectory);
OutputStream out = new FileOutputStream(newFile); final OutputStream out = new FileOutputStream(newFile);
try { try {
OutputStream wrappedOut = null;
if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) { if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) {
out = new QuotedPrintableOutputStream(out, false); wrappedOut = new QuotedPrintableOutputStream(out, false);
} else if (MimeUtil.ENC_BASE64.equals(encoding)) { } else if (MimeUtil.ENC_BASE64.equals(encoding)) {
out = new Base64OutputStream(out); wrappedOut = new Base64OutputStream(out);
} else { } else {
throw new RuntimeException("Target encoding not supported: " + encoding); throw new RuntimeException("Target encoding not supported: " + encoding);
} }
InputStream in = getInputStream(); InputStream in = getInputStream();
try { try {
IOUtils.copy(in, out); IOUtils.copy(in, wrappedOut);
} finally { } finally {
in.close(); IOUtils.closeQuietly(in);
IOUtils.closeQuietly(wrappedOut);
} }
} finally { } finally {
out.close(); IOUtils.closeQuietly(out);
} }
mFile = newFile; mFile = newFile;
@ -100,7 +102,7 @@ public class BinaryTempFileBody implements RawDataBody, SizeAware {
try { try {
IOUtils.copy(in, out); IOUtils.copy(in, out);
} finally { } finally {
in.close(); IOUtils.closeQuietly(in);
} }
} }

View File

@ -46,7 +46,7 @@ public class BinaryTempFileMessageBody extends BinaryTempFileBody implements Com
IOUtils.copy(in, out); IOUtils.copy(in, out);
} }
} finally { } finally {
in.close(); IOUtils.closeQuietly(in);
} }
} }

View File

@ -1404,7 +1404,7 @@ public class Account implements BaseAccount, StoreConfig {
if (i < identities.size()) { if (i < identities.size()) {
return identities.get(i); return identities.get(i);
} }
return null; throw new IllegalArgumentException("Identity with index " + i + " not found");
} }
public boolean isAnIdentity(Address[] addrs) { public boolean isAnIdentity(Address[] addrs) {

View File

@ -1183,41 +1183,40 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
if (menuInfo != null) { if (menuInfo != null) {
mSelectedContextAccount = (BaseAccount)getListView().getItemAtPosition(menuInfo.position); mSelectedContextAccount = (BaseAccount)getListView().getItemAtPosition(menuInfo.position);
} }
Account realAccount = null;
if (mSelectedContextAccount instanceof Account) { if (mSelectedContextAccount instanceof Account) {
realAccount = (Account)mSelectedContextAccount; Account realAccount = (Account)mSelectedContextAccount;
} switch (item.getItemId()) {
switch (item.getItemId()) { case R.id.delete_account:
case R.id.delete_account: onDeleteAccount(realAccount);
onDeleteAccount(realAccount); break;
break; case R.id.account_settings:
case R.id.account_settings: onEditAccount(realAccount);
onEditAccount(realAccount); break;
break; case R.id.activate:
case R.id.activate: onActivateAccount(realAccount);
onActivateAccount(realAccount); break;
break; case R.id.clear_pending:
case R.id.clear_pending: onClearCommands(realAccount);
onClearCommands(realAccount); break;
break; case R.id.empty_trash:
case R.id.empty_trash: onEmptyTrash(realAccount);
onEmptyTrash(realAccount); break;
break; case R.id.clear:
case R.id.clear: onClear(realAccount);
onClear(realAccount); break;
break; case R.id.recreate:
case R.id.recreate: onRecreate(realAccount);
onRecreate(realAccount); break;
break; case R.id.export:
case R.id.export: onExport(false, realAccount);
onExport(false, realAccount); break;
break; case R.id.move_up:
case R.id.move_up: onMove(realAccount, true);
onMove(realAccount, true); break;
break; case R.id.move_down:
case R.id.move_down: onMove(realAccount, false);
onMove(realAccount, false); break;
break; }
} }
return true; return true;
} }

View File

@ -1024,15 +1024,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
} }
private String getFolderNameById(Account account, long folderId) { private String getFolderNameById(Account account, long folderId) {
try { Folder folder = getFolderById(account, folderId);
Folder folder = getFolderById(account, folderId); if (folder != null) {
if (folder != null) { return folder.getName();
return folder.getName();
}
} catch (Exception e) {
Log.e(K9.LOG_TAG, "getFolderNameById() failed.", e);
} }
return null; return null;
} }
@ -1042,9 +1037,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
LocalFolder localFolder = localStore.getFolderById(folderId); LocalFolder localFolder = localStore.getFolderById(folderId);
localFolder.open(Folder.OPEN_MODE_RO); localFolder.open(Folder.OPEN_MODE_RO);
return localFolder; return localFolder;
} catch (Exception e) { } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "getFolderNameById() failed.", e); throw new RuntimeException(e);
return null;
} }
} }
@ -3162,10 +3156,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
try { try {
return folder.getMessage(uid); return folder.getMessage(uid);
} catch (MessagingException e) { } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Something went wrong while fetching a message", e); throw new RuntimeException(e);
} }
return null;
} }
private List<LocalMessage> getCheckedMessages() { private List<LocalMessage> getCheckedMessages() {

View File

@ -4,7 +4,9 @@ package com.fsck.k9.helper;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@ -136,18 +138,23 @@ public class HtmlConverterTest {
if (!WRITE_TO_FILE) { if (!WRITE_TO_FILE) {
return; return;
} }
FileWriter fstream = null;
try { try {
System.err.println(content); System.err.println(content);
File f = new File(OUTPUT_FILE); File f = new File(OUTPUT_FILE);
f.delete(); f.delete();
FileWriter fstream = new FileWriter(OUTPUT_FILE); fstream = new FileWriter(OUTPUT_FILE);
BufferedWriter out = new BufferedWriter(fstream); BufferedWriter out = new BufferedWriter(fstream);
out.write(content); out.write(content);
out.close(); out.close();
} catch (Exception e) { } catch (IOException e) {
e.printStackTrace(); throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(fstream);
} }
} }