Skip to content

Commit

Permalink
fix: use safe cast in KeeperRecordData.getField()
Browse files Browse the repository at this point in the history
Replace unsafe cast (as T) with safe cast operator (as? T) in getField()
to prevent NPE when uploading files to records without FileRef field.

This fixes an issue where attempting to upload a file to a record
without an initialized FileRef field would throw:
"null cannot be cast to non-null type FileRef"

Fixes #698
  • Loading branch information
maksimu committed Jan 4, 2025
1 parent d8f82e6 commit 5d004ce
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class KeeperRecordData @JvmOverloads constructor(
var notes: String? = null
) {
inline fun <reified T> getField(): T? {
return (fields + custom).find { x -> x is T } as T
return (fields + (custom ?: listOf())).find { x -> x is T } as? T
}

fun getField(clazz: Class<out KeeperRecordField>): KeeperRecordField? {
Expand Down

0 comments on commit 5d004ce

Please sign in to comment.