Skip to content

Commit

Permalink
Avoid NullPointerExceptions when unboxing
Browse files Browse the repository at this point in the history
  • Loading branch information
cketti committed May 5, 2020
1 parent e305d91 commit 1717ede
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1886,8 +1886,13 @@ public void expunge(Account account, long folderId) {
public void deleteDraft(final Account account, long id) {
LocalFolder localFolder = null;
try {
Long folderId = account.getDraftsFolderId();
if (folderId == null) {
Timber.w("No Drafts folder configured. Can't delete draft.");
return;
}

LocalStore localStore = localStoreProvider.getInstance(account);
long folderId = account.getDraftsFolderId();
localFolder = localStore.getFolder(folderId);
localFolder.open();
String uid = localFolder.getMessageUidById(id);
Expand Down Expand Up @@ -2135,8 +2140,13 @@ public void emptyTrash(final Account account, MessagingListener listener) {
public void run() {
LocalFolder localFolder = null;
try {
Long trashFolderId = account.getTrashFolderId();
if (trashFolderId == null) {
Timber.w("No Trash folder configured. Can't empty trash.");
return;
}

LocalStore localStore = localStoreProvider.getInstance(account);
long trashFolderId = account.getTrashFolderId();
localFolder = localStore.getFolder(trashFolderId);
localFolder.open();
String trashFolderServerId = localFolder.getServerId();
Expand Down Expand Up @@ -2567,8 +2577,13 @@ public void deleteAccount(Account account) {
public Message saveDraft(final Account account, final Message message, long existingDraftId, String plaintextSubject, boolean saveRemotely) {
LocalMessage localMessage = null;
try {
Long draftsFolderId = account.getDraftsFolderId();
if (draftsFolderId == null) {
throw new IllegalStateException("No Drafts folder configured");
}

LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderId());
LocalFolder localFolder = localStore.getFolder(draftsFolderId);
localFolder.open();

if (existingDraftId != INVALID_MESSAGE_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class AccountSearchConditions {
excludeSpecialFolder(search, account.spamFolderId)
excludeSpecialFolder(search, account.outboxFolderId)
excludeSpecialFolder(search, account.sentFolderId)
search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolderId!!.toString()))
account.inboxFolderId?.let { inboxFolderId ->
search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, inboxFolderId.toString()))
}
}

/**
Expand All @@ -97,7 +99,9 @@ class AccountSearchConditions {
excludeSpecialFolder(search, account.trashFolderId)
excludeSpecialFolder(search, account.spamFolderId)
excludeSpecialFolder(search, account.outboxFolderId)
search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, account.inboxFolderId.toString()))
account.inboxFolderId?.let { inboxFolderId ->
search.or(SearchCondition(SearchField.FOLDER, Attribute.EQUALS, inboxFolderId.toString()))
}
}

private fun excludeSpecialFolder(search: LocalSearch, folderId: Long?) {
Expand Down
3 changes: 2 additions & 1 deletion app/ui/src/main/java/com/fsck/k9/activity/MessageList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,8 @@ public void openMessage(MessageReference messageReference) {
Account account = preferences.getAccount(messageReference.getAccountUuid());
long folderId = messageReference.getFolderId();

if (folderId == account.getDraftsFolderId()) {
Long draftsFolderId = account.getDraftsFolderId();
if (draftsFolderId != null && folderId == draftsFolderId) {
MessageActions.actionEditDraft(this, messageReference);
} else {
if (messageListFragment != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ private void delete() {
}
}

public void onRefile(long dstFolderId) {
if (!mController.isMoveCapable(mAccount)) {
public void onRefile(Long dstFolderId) {
if (dstFolderId == null || !mController.isMoveCapable(mAccount)) {
return;
}
if (!mController.isMoveCapable(mMessageReference)) {
Expand All @@ -331,7 +331,7 @@ public void onRefile(long dstFolderId) {
return;
}

if (dstFolderId == mAccount.getSpamFolderId() && K9.isConfirmSpam()) {
if (dstFolderId.equals(mAccount.getSpamFolderId()) && K9.isConfirmSpam()) {
destinationFolderId = dstFolderId;
showDialog(R.id.dialog_confirm_spam);
} else {
Expand Down

0 comments on commit 1717ede

Please sign in to comment.