Fix NPE with empty files

This commit is contained in:
Naveen 2023-05-02 17:24:12 +05:30
parent e26e43cd91
commit c2ff80b9e5
1 changed files with 1 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class NotesImporter(private val context: Context) {
val json = reader.readText() val json = reader.readText()
val type = object : TypeToken<List<Note>>() {}.type val type = object : TypeToken<List<Note>>() {}.type
val notes = gson.fromJson<List<Note>>(json, type) val notes = gson.fromJson<List<Note>>(json, type)
val totalNotes = notes.size val totalNotes = notes?.size ?: 0
if (totalNotes <= 0) { if (totalNotes <= 0) {
callback.invoke(ImportResult.IMPORT_NOTHING_NEW) callback.invoke(ImportResult.IMPORT_NOTHING_NEW)
return@ensureBackgroundThread return@ensureBackgroundThread