@@ -27,11 +27,13 @@ internal object ResolverCompat {
2727 )
2828
2929 private fun getStringOrDefault (cursor : Cursor , index : Int , default : String = ""): String {
30- return if (index != - 1 ) cursor.getString(index) else default
30+ if (index == - 1 || cursor.isNull(index)) return default
31+ return cursor.getString(index) ? : default
3132 }
3233
3334 private fun getLongOrDefault (cursor : Cursor , index : Int , default : Long = 0L): Long {
34- return if (index != - 1 ) cursor.getLong(index) else default
35+ if (index == - 1 || cursor.isNull(index)) return default
36+ return cursor.getLong(index)
3537 }
3638
3739 /* *
@@ -143,7 +145,7 @@ internal object ResolverCompat {
143145 if (itemCount > 10 ) listOfDocuments.ensureCapacity(itemCount)
144146
145147 // Resolve column indices dynamically
146- val idIndex = cursor.getColumnIndex (Document .COLUMN_DOCUMENT_ID )
148+ val idIndex = cursor.getColumnIndexOrThrow (Document .COLUMN_DOCUMENT_ID )
147149
148150 val nameIndex = cursor.getColumnIndex(Document .COLUMN_DISPLAY_NAME )
149151 val sizeIndex = cursor.getColumnIndex(Document .COLUMN_SIZE )
@@ -152,7 +154,7 @@ internal object ResolverCompat {
152154 val flagsIndex = cursor.getColumnIndex(Document .COLUMN_FLAGS )
153155
154156 while (cursor.moveToNext()) {
155- val documentId = cursor.getString(idIndex)
157+ val documentId = cursor.getString(idIndex) ? : continue
156158 val documentUri = DocumentsContract .buildDocumentUriUsingTree(uri, documentId)
157159
158160 val documentName = getStringOrDefault(cursor, nameIndex)
0 commit comments