Skip to content

Commit 32dfdf9

Browse files
authored
Merge pull request #2971 from TeamAmaze/emmanuelmess/fix/otgutil_npe
Fix NPE on OTGUtil.getDocumentFiles
2 parents e44fa03 + 7b30bae commit 32dfdf9

File tree

1 file changed

+8
-2
lines changed
  • app/src/main/java/com/amaze/filemanager/utils

1 file changed

+8
-2
lines changed

app/src/main/java/com/amaze/filemanager/utils/OTGUtil.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ object OTGUtil {
9898
fileFound: OnFileFound
9999
) {
100100
var rootUri = DocumentFile.fromTreeUri(context, rootUriString)
101+
101102
val parts: Array<String> = if (openMode == OpenMode.DOCUMENT_FILE) {
102103
path.substringAfter(rootUriString.toString())
103104
.split("/", PATH_SEPARATOR_ENCODED).toTypedArray()
@@ -110,11 +111,16 @@ object OTGUtil {
110111
if (part == "otg:" || part == "" || part == "content:") continue
111112

112113
// iterating through the required path to find the end point
113-
rootUri = rootUri!!.findFile(part)
114+
rootUri = rootUri?.findFile(part)
115+
}
116+
117+
if (rootUri == null) {
118+
Log.e(TAG, "Null DocumentFile listed!")
119+
return
114120
}
115121

116122
// we have the end point DocumentFile, list the files inside it and return
117-
for (file in rootUri!!.listFiles()) {
123+
for (file in rootUri.listFiles()) {
118124
if (file.exists()) {
119125
var size: Long = 0
120126
if (!file.isDirectory) size = file.length()

0 commit comments

Comments
 (0)