Skip to content

Commit

Permalink
Merge pull request #3213 from k9mail/GH-1220_crash_on_duplicate_folder
Browse files Browse the repository at this point in the history
Crash when trying to create a folder that already exists
  • Loading branch information
cketti authored Feb 26, 2018
2 parents 6227058 + 2ec44b6 commit 5152d04
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,24 @@ public void createFolders(final List<LocalFolder> foldersToCreate, final int vis
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
for (LocalFolder folder : foldersToCreate) {
String name = folder.getName();

if (K9.DEVELOPER_MODE) {
Cursor cursor = db.query("folders", new String[] { "id", "name" },
"name = ?", new String[] { name },null, null, null);
try {
if (cursor.moveToNext()) {
long folderId = cursor.getLong(0);
String folderName = cursor.getString(1);

throw new AssertionError("Tried to create folder '" + name + "'" +
" that already exists in the database as '" + folderName + "'" +
" (" + folderId + ")");
}
} finally {
cursor.close();
}
}

final LocalFolder.PreferencesHolder prefHolder = folder.new PreferencesHolder();

// When created, special folders should always be displayed
Expand Down

0 comments on commit 5152d04

Please sign in to comment.