From 6f453faf067a41276dd8fd42cdb89c8a9b4db221 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 10 Mar 2019 16:17:27 +0000 Subject: [PATCH] Import: cleanup code a bit. This should make it easier to debug null errors. --- .../syncadapter/ui/importlocal/ImportFragment.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt index 68cae7d7..d1d0bee5 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt @@ -210,6 +210,7 @@ class ImportFragment : DialogFragment() { val result = ImportResult() try { + val context = context!! val importReader = InputStreamReader(inputStream) if (info.type == CollectionInfo.Type.CALENDAR) { @@ -226,7 +227,7 @@ class ImportFragment : DialogFragment() { finishParsingFile(events.size) - val provider = context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!! + val provider = context.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!! val localCalendar: LocalCalendar? try { localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!) @@ -256,7 +257,7 @@ class ImportFragment : DialogFragment() { } } else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) { val oldUidToNewId = HashMap() - val downloader = ContactsSyncManager.ResourceDownloader(context!!) + val downloader = ContactsSyncManager.ResourceDownloader(context) val contacts = Contact.fromReader(importReader, downloader) if (contacts.size == 0) { @@ -269,8 +270,11 @@ class ImportFragment : DialogFragment() { finishParsingFile(contacts.size) - val provider = context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!! - val localAddressBook = LocalAddressBook.findByUid(context!!, provider, account, info.uid!!)!! + val provider = context.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!! + val localAddressBook = LocalAddressBook.findByUid(context, provider, account, info.uid!!) + if (localAddressBook == null) { + throw FileNotFoundException("Failed to load local address book.") + } for (contact in contacts.filter { contact -> !contact.group }) { try {