Reputation: 1810
This is Kotlin, not Java, FYI.
I have a DialogFragment subclass that I'm using, and I'm getting some crashes when it's dismissed. It doesn't happen every time, and I can't seem to find a pattern to it. The crash is happening inside the overridden onDismiss()
function, as an automatic Kotlin Intrinstics.checkParameterIsNotNull()
call. Here is the decompiled Kotlin->Java code from my dialog subclass:
public void onDismiss(@NotNull DialogInterface dialog) {
Intrinsics.checkParameterIsNotNull(dialog, "dialog");
super.onDismiss(dialog);
}
And here is the crash message:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter dialog
at com.foo.MyDialogFragment.onDismiss(Unknown Source:2)
This is the DialogInterface parameter, and it is happening before any of my code runs, so I cannot do anything to prevent it. It's not possible to put a check before this, because the Kotlin compiler inserts the null-check before any of my code.
I am dismissing the dialog by calling this, inside the owning Activity's onStop()
myDialog?.dismissAllowingStateLoss()
Any idea what is causing this, and more importantly, what can I do? It seems like this should not ever be happening, because the interface specifies it cannot be null
.
Upvotes: 1
Views: 267
Reputation: 67259
This may be due to this bug on the Android issue tracker, which was fixed in version androidx.fragment version 1.2.0. Updating to that version of androidx.fragment should resolve the issue.
Specifically it appears to be an issue with the timing of cancel/dismiss callbacks when the dialog has already been destroyed.
Upvotes: 1