Repository: eventfahrplan/eventfahrplan
Issue: Crash on notification receive: NullPointerException: Attempt to invoke interface method 'java.lang.Object kotlin.Lazy.getValue()' on a null object reference

Crash report from @johnjohndoe:

- sent: 25.08.2018
- [1.34.0 (FrOSCon Edition)](https://github.com/johnjohndoe/CampFahrplan/releases/tag/v.1.34.0-FrOSCon-Edition)
- Android version: 9
- Device model: Pixel 2

# Stacktrace
``` java
java.lang.RuntimeException: Unable to start receiver 
    nerd.tuxmobil.fahrplan.congress.alarms.AlarmReceiver: java.lang.NullPointerException: 
    Attempt to invoke interface method 'java.lang.Object kotlin.Lazy.getValue()' 
    on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3388)
at android.app.ActivityThread.access$1200(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 
    'java.lang.Object kotlin.Lazy.getValue()' on a null object reference
at nerd.tuxmobil.fahrplan.congress.notifications.NotificationHelper.getNotificationManager(Unknown Source:7)
at nerd.tuxmobil.fahrplan.congress.notifications.NotificationHelper.createNotificationChannel(NotificationHelper.kt:63)
at nerd.tuxmobil.fahrplan.congress.notifications.NotificationHelper.<init>(NotificationHelper.kt:19)
at nerd.tuxmobil.fahrplan.congress.alarms.AlarmReceiver.onReceive(AlarmReceiver.java:60)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3379)
... 8 more

```

# Log
``` java
Log:
0 D: Writing unhandled exception to: /data/user/0/info.metadude.android.froscon.schedule/files/1.34.0 (FrOSCon Edition)-1535232960071.tracedroid
1 D: onReceive: lecture_id: 2276, intent: Intent { act=nerd.tuxmobil.fahrplan.congress.ALARM_LECTURE dat=alarm://2276 flg=0x14 cmp=info.metadude.android.froscon.schedule/nerd.tuxmobil.fahrplan.congress.alarms.AlarmReceiver (has extras) }
2 D: Add alarm for lecture: 2276, alarmTimesIndex: 2
3 D: current handler class=com.android.internal.os.RuntimeInit$KillApplicationHandler
```

# How to reproduce
1. Set the system date to the date of the conference.
2. Schedule an alarm for an event in the past of the current day.

# Expected behavior
- Notification for the event alarm shows up.

# Observed behavior
- App crashes.

# Reproducibility
- The crash **can** be reproduced on a Nexus 5X emulator running Android 9 (API 28).
- The crash **can** be reproduced on a Nexus 5X emulator running Android 8.1.0 (API 27).
- The crash **can** be reproduced on a Nexus 5X emulator running Android 8.0.0 (API 26).
- The crash **cannot** be reproduced on a Nexus 5X emulator running Android 7.1.1 (API 25).
- The crash **cannot** be reproduced on a Nexus 5 device running Android 6.0.1 (API 23).

Changed files:
app/src/main/java/nerd/tuxmobil/fahrplan/congress/notifications/NotificationHelper.kt

diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/notifications/NotificationHelper.kt b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/notifications/NotificationHelper.kt
index 1d6c0fd4..a93e0729 100644
--- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/notifications/NotificationHelper.kt
+++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/notifications/NotificationHelper.kt
@@ -15,6 +15,10 @@ import nerd.tuxmobil.fahrplan.congress.extensions.getNotificationManager
 
 internal class NotificationHelper(context: Context) : ContextWrapper(context) {
 
+    private val notificationManager: NotificationManager by lazy {
+        getNotificationManager()
+    }
+
     init {
         createNotificationChannel(EVENT_ALARM_CHANNEL_ID, eventAlarmChannelName, eventAlarmChannelDescription)
         createNotificationChannel(SCHEDULE_UPDATE_CHANNEL_ID, scheduleUpdateChannelName, scheduleUpdateChannelDescription)
@@ -106,10 +110,6 @@ internal class NotificationHelper(context: Context) : ContextWrapper(context) {
     private val smallIcon: Int
         get() = R.drawable.ic_notification
 
-    private val notificationManager: NotificationManager by lazy {
-        getNotificationManager()
-    }
-
     companion object {
         private const val EVENT_ALARM_CHANNEL_ID = "EVENT_ALARM_CHANNEL"
         private const val SCHEDULE_UPDATE_CHANNEL_ID = "SCHEDULE_UPDATE_CHANNEL"