Repository: thundernest/k-9
Issue: Crash: `UninitializedPropertyAccessException` in `MessageList.dispatchKeyEvent()`

### Checklist

- [X] I have used the search function to see if someone else has already submitted the same bug report.
- [X] I will describe the problem with as much detail as possible.

### App version

5.913

### Where did you get the app from?

Google Play

### Android version

various (Android 9-12)

### Device model

various

### Steps to reproduce

Unclear. Presumably press a key on a hardware keyboard before the message list screen is properly initialized.

### Expected behavior

No crash

### Actual behavior

Crash

### Logs

Stacktrace via Google Play developer console:

```text
kotlin.UninitializedPropertyAccessException: 
  at com.fsck.k9.activity.MessageList.dispatchKeyEvent (MessageList.kt:681)
  at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent (WindowCallbackWrapper.java:59)
  at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent (AppCompatDelegateImpl.java:3090)
  at com.android.internal.policy.DecorView.dispatchKeyEvent (DecorView.java:396)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent (ViewRootImpl.java:6342)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:6210)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5680)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5737)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5703)
  at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5855)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5711)
  at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5912)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5684)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5737)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5703)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5711)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5684)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5737)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5703)
  at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5855)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5711)
  at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5912)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5684)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5737)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5703)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5711)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5684)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5737)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5703)
  at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5855)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5711)
  at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5912)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5684)
  at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:8584)
  at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:8535)
  at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:8433)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:8707)
  at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:221)
  at android.os.MessageQueue.nativePollOnce (Native Method)
  at android.os.MessageQueue.next (MessageQueue.java:335)
  at android.os.Looper.loop (Looper.java:183)
  at android.app.ActivityThread.main (ActivityThread.java:8030)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:631)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:978)
```

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index da6bce71a..d671d6bb1 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -675,7 +675,7 @@ open class MessageList :
 
     override fun dispatchKeyEvent(event: KeyEvent): Boolean {
         var eventHandled = false
-        if (event.action == KeyEvent.ACTION_DOWN && searchView.isIconified) {
+        if (event.action == KeyEvent.ACTION_DOWN && ::searchView.isInitialized && searchView.isIconified) {
             eventHandled = onCustomKeyDown(event)
         }