From 8d1befd34cca9bd6ab18c4978d5730c86ba052c3 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 31 Mar 2020 14:49:05 -0700 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/9561: Fix initialization order in HomeMenu `init` blocks are executed before `val` initialization which is declared afterwards in the class. In this case, we had `quitItem` and `reconnectToSyncItem` as lazy, but declared after the `init` block which may need them. And so, while this compiles just fine, in practice we run into an NPE as the `init` block tries to get the lazy's value. Simply re-ordering initialization fixes the problem. --- .../java/org/mozilla/fenix/home/HomeMenu.kt | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 32de42a9f8..19581bbaea 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -51,6 +51,32 @@ class HomeMenu( private val menuCategoryTextColor = ThemeManager.resolveAttribute(R.attr.menuCategoryText, context) + // 'Reconnect' and 'Quit' items aren't needed most of the time, so we'll only create the if necessary. + private val reconnectToSyncItem by lazy { + BrowserMenuHighlightableItem( + context.getString(R.string.sync_reconnect), + R.drawable.ic_sync_disconnected, + iconTintColorResource = syncDisconnectedColor, + textColorResource = primaryTextColor, + highlight = BrowserMenuHighlight.HighPriority( + backgroundTint = syncDisconnectedBackgroundColor + ), + isHighlighted = { true } + ) { + onItemTapped.invoke(Item.Sync) + } + } + + private val quitItem by lazy { + BrowserMenuImageText( + context.getString(R.string.delete_browsing_data_on_quit_action), + R.drawable.ic_exit, + primaryTextColor + ) { + onItemTapped.invoke(Item.Quit) + } + } + private val coreMenuItems by lazy { val whatsNewItem = BrowserMenuHighlightableItem( context.getString(R.string.browser_menu_whats_new), @@ -144,30 +170,4 @@ class HomeMenu( }, lifecycleOwner) } } - - // 'Reconnect' and 'Quit' items aren't needed most of the time, so we'll only create the if necessary. - private val reconnectToSyncItem by lazy { - BrowserMenuHighlightableItem( - context.getString(R.string.sync_reconnect), - R.drawable.ic_sync_disconnected, - iconTintColorResource = syncDisconnectedColor, - textColorResource = primaryTextColor, - highlight = BrowserMenuHighlight.HighPriority( - backgroundTint = syncDisconnectedBackgroundColor - ), - isHighlighted = { true } - ) { - onItemTapped.invoke(Item.Sync) - } - } - - private val quitItem by lazy { - BrowserMenuImageText( - context.getString(R.string.delete_browsing_data_on_quit_action), - R.drawable.ic_exit, - primaryTextColor - ) { - onItemTapped.invoke(Item.Quit) - } - } }