Skip to content

Commit e1c5f59

Browse files
committed
🚑️ [Android] Fix potential NPE when moving assets
1 parent 61b02d2 commit e1c5f59

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/Android30DbUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ object Android30DbUtils : IDBUtils {
653653
}
654654
}
655655

656-
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String>? {
656+
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String?>? {
657657
val cr = context.contentResolver
658658
val cursor = cr.query(
659659
allUri,
@@ -668,7 +668,7 @@ object Android30DbUtils : IDBUtils {
668668
}
669669
val galleryID = cursor.getString(0)
670670
val path = cursor.getString(1)
671-
return Pair(galleryID, File(path).parent!!)
671+
return Pair(galleryID, File(path).parent)
672672
}
673673
}
674674

android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ object AndroidQDBUtils : IDBUtils {
673673
}
674674
}
675675

676-
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String>? {
676+
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String?>? {
677677
val cursor = context.contentResolver.query(
678678
allUri,
679679
arrayOf(BUCKET_ID, RELATIVE_PATH),
@@ -687,7 +687,7 @@ object AndroidQDBUtils : IDBUtils {
687687
}
688688
val galleryID = cursor.getString(0)
689689
val path = cursor.getString(1)
690-
return Pair(galleryID, File(path).parent!!)
690+
return Pair(galleryID, File(path).parent)
691691
}
692692
}
693693

android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,25 +664,21 @@ object DBUtils : IDBUtils {
664664
* 0 : gallery id
665665
* 1 : current asset parent path
666666
*/
667-
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String>? {
667+
override fun getSomeInfo(context: Context, assetId: String): Pair<String, String?>? {
668668
val cursor = context.contentResolver.query(
669669
allUri,
670670
arrayOf(MediaStore.Files.FileColumns.BUCKET_ID, MediaStore.Files.FileColumns.DATA),
671671
"${MediaStore.Files.FileColumns._ID} = ?",
672672
arrayOf(assetId),
673673
null
674-
)
675-
?: return null
676-
674+
) ?: return null
677675
cursor.use {
678676
if (!cursor.moveToNext()) {
679677
return null
680678
}
681-
682679
val galleryID = cursor.getString(0)
683680
val path = cursor.getString(1)
684-
685-
return Pair(galleryID, File(path).parent!!)
681+
return Pair(galleryID, File(path).parent)
686682
}
687683
}
688684

android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ interface IDBUtils {
358358

359359
fun moveToGallery(context: Context, assetId: String, galleryId: String): AssetEntity?
360360

361-
fun getSomeInfo(context: Context, assetId: String): Pair<String, String>?
361+
fun getSomeInfo(context: Context, assetId: String): Pair<String, String?>?
362362

363363
fun getUri(id: String, type: Int, isOrigin: Boolean = false): Uri {
364364
var uri = when (type) {

0 commit comments

Comments
 (0)