Modern Apps git

← Modern-Apps.git

wordmaker: guard definition lookup before dictionary init

Commit
3f22cb7878a63cfdfeaf2dd3cc487a6be3e641f2
Author
Vayun Mathur <[email protected]>
When
2026-11-19 02:30 UTC (17 days ago)
Parents
e5f5dd2
Dictionary.getDefinition dereferenced the lateinit appContext
with no init gate, unlike contains() which checks loaded. The
ViewModel starts init() as a fire-and-forget IO launch, so tapping
a found or bonus word before it finished (or after a failed asset
read) threw UninitializedPropertyAccessException or an uncaught
Brotli/IO failure.

The lookup now returns no definitions until initialized and
contains asset-load failures.

Verified: ./gradlew :games:wordmaker:testDevUnitTest (pass),
./check games/wordmaker (pass).

Diff

games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.ktindex 7f99321d44..d057f0b732 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/domain/Dictionary.kt@@ -57,8 +57,15 @@ class Dictionary {         return false     } -    fun getDefinition(word: String): List<String> =-        (definitions ?: loadDefinitions())[word.lowercase()] ?: emptyList()+    fun getDefinition(word: String): List<String> {+        // Tapping a word before the fire-and-forget init() finished (or+        // after it failed) must show no definition, not crash on the+        // lateinit context or a failed asset read.+        if (!::appContext.isInitialized) return emptyList()+        return runCatching {+            (definitions ?: loadDefinitions())[word.lowercase()] ?: emptyList()+        }.getOrDefault(emptyList())+    }      @Synchronized     private fun loadDefinitions(): Map<String, List<String>> {