Skip to content

Commit f4794f8

Browse files
Merge pull request #16870 from nextcloud/backport/16863/stable-33.1.0
[stable-33.1.0] fix(file-extension): to file, npe
2 parents a00a765 + 59b1f2b commit f4794f8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

app/src/androidTest/java/com/nextcloud/extensions/BitmapDecodeTests.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class BitmapDecodeTests {
6969
assertNull(result)
7070
}
7171

72+
@Test
73+
fun testToFileWhenPathIsNullShouldReturnNull() {
74+
val result = null.toFile()
75+
assertNull(result)
76+
}
77+
7278
@Test
7379
fun testToFileWhenFileDoesNotExistShouldReturnNull() {
7480
val nonExistentPath = tempDir.resolve("does_not_exist.jpg")

app/src/main/java/com/nextcloud/utils/extensions/FileExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fun Path.toLocalPath(): String = toAbsolutePath().toString()
3737
* @return [File] instance if the file exists, or `null` if the path is null, empty, or non-existent.
3838
*/
3939
@Suppress("ReturnCount")
40-
fun String.toFile(): File? {
40+
fun String?.toFile(): File? {
4141
if (isNullOrEmpty()) {
4242
Log_OC.w(TAG, "given path is null or empty: $this")
4343
return null

0 commit comments

Comments
 (0)