calendar: do not crash agenda widget on a missing day
- Commit
a8e8049d0e6dcdbc0ab4811af1bd64a8c1a83013- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 02:07 UTC (17 days ago)
- Parents
bcb9de2
CalendarGlanceWidget.Content recomputes its day range from today at render time but indexes the data map, keyed by the days loadData saw, with !!. A widget rendering after midnight (or with any stale or partial data) asks for a day the map has no entry for, throwing NullPointerException inside the Glance widget. Treat a missing day as an empty day with orEmpty and reuse that list for the items call. Verified: ./gradlew :calendar:testDevUnitTest and ./check calendar both pass.
Diff
calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.kt b/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.ktindex 7815206f0e..b849251bc4 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.kt@@ -152,12 +152,16 @@ fun Content(context: Context, positionedEvents: Map<LocalDate, List<Instance>>) ) { LazyColumn(modifier = GlanceModifier.fillMaxSize().background(GlanceTheme.colors.surface)) { for(day in days) {- if(positionedEvents[day]!!.isNotEmpty()) {+ // The map was keyed by the days loadData saw; rendering can+ // run after midnight (or with any stale/partial data), so a+ // missing day is an empty day, not a crash in the widget.+ val dayEvents = positionedEvents[day].orEmpty()+ if(dayEvents.isNotEmpty()) { item { DayHeader(dayHeaderLabel(day, today, context)) } }- items(positionedEvents[day]!!) { instance ->+ items(dayEvents) { instance -> CalendarEventRow( color = instance.color, title = instance.eventTitle,