Pārlūkot izejas kodu

Merge pull request #1355 from nextcloud/mediaFolderNPE

Prevent NPE on absolutePath
Tobias Kaminsky 7 gadi atpakaļ
vecāks
revīzija
c76f862ddf

+ 1 - 1
scripts/lint/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 1 error and 581 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 1 error and 581 warnings</span>

+ 7 - 4
src/main/java/com/owncloud/android/datamodel/MediaProvider.java

@@ -137,7 +137,7 @@ public class MediaProvider {
                     cursorImages.close();
 
                     // only do further work if folder is not within the Nextcloud app itself
-                    if (!mediaFolder.absolutePath.startsWith(dataPath)) {
+                    if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
 
                         // count images
                         Cursor count = contentResolver.query(
@@ -225,13 +225,16 @@ public class MediaProvider {
                     while (cursorImages.moveToNext()) {
                         filePath = cursorImages.getString(cursorImages.getColumnIndexOrThrow(
                                 MediaStore.MediaColumns.DATA));
-                        mediaFolder.filePaths.add(filePath);
-                        mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
+
+                        if (filePath != null) {
+                            mediaFolder.filePaths.add(filePath);
+                            mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
+                        }
                     }
                     cursorImages.close();
 
                     // only do further work if folder is not within the Nextcloud app itself
-                    if (!mediaFolder.absolutePath.startsWith(dataPath)) {
+                    if (mediaFolder.absolutePath != null && !mediaFolder.absolutePath.startsWith(dataPath)) {
 
                         // count images
                         Cursor count = contentResolver.query(