Use fatalError instead of NPE

Signed-off-by: Johannes Marbach <johannesm@element.io>
This commit is contained in:
Johannes Marbach 2022-05-31 13:42:31 +02:00
parent 3cc1951587
commit 4fc6cb1de3
1 changed files with 10 additions and 2 deletions

View File

@ -24,11 +24,15 @@ import androidx.annotation.VisibleForTesting
import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.error.fatalError
import im.vector.app.core.utils.checkPermissions
import im.vector.app.features.settings.VectorPreferences
import java.lang.NullPointerException
import javax.inject.Inject
class WebviewPermissionUtils @Inject constructor() {
class WebviewPermissionUtils @Inject constructor(
private val vectorPreferences: VectorPreferences,
) {
private var permissionRequest: PermissionRequest? = null
private var selectedPermissions = listOf<String>()
@ -75,7 +79,11 @@ class WebviewPermissionUtils @Inject constructor() {
fun onPermissionResult(result: Map<String, Boolean>) {
if (permissionRequest == null) {
throw NullPointerException("permissionRequest was null! Make sure to call promptForPermissions first.")
fatalError(
message = "permissionRequest was null! Make sure to call promptForPermissions first.",
failFast = vectorPreferences.failFast()
)
return
}
val grantedPermissions = filterPermissionsToBeGranted(selectedPermissions, result)
if (grantedPermissions.isNotEmpty()) {