00-banned-antipatterns.md
.codex/skills/compose-kotlin-agent-skills/references/00-banned-antipatterns.md
1---2name: banned-antipatterns3description: >4 Master lookup table of AI-hallucinated Android/Kotlin/Compose patterns with WRONG/RIGHT5 fixes. Use when reviewing agent output, auditing PRs, or before merging generated code.6version: "2.2.0"7updated: "2026-05-21"8---910# Banned Antipatterns — AI Hallucination Lookup1112Load this file before reviewing any agent-generated Kotlin. Every row is a production bug waiting to ship.1314| # | Banned (WRONG) | Correct (RIGHT) | Why it breaks |15|---|----------------|-----------------|---------------|16| 1 | `GlobalScope.launch { }` | `viewModelScope.launch { }` | Leaks past lifecycle |17| 2 | `runBlocking { }` on main | `suspend` + proper scope | ANR |18| 3 | `Text("Hello")` in UI | `stringResource(R.string.hello)` | No localization |19| 4 | `collectAsState()` Android | `collectAsStateWithLifecycle()` | Background battery drain |20| 5 | `_state.value = x` | `_state.update { x }` | Race + non-atomic |21| 6 | `mutableStateListOf` in VM | `StateFlow<List<T>>` + immutable list | Not snapshot-safe |22| 7 | `items(list)` no key | `items(list, key = { it.id })` | Lost item state |23| 8 | Pass `ViewModel` to child | Pass lambdas / state | Broken previews + tight coupling |24| 9 | `remember { mutableStateOf }` for screen state | ViewModel `StateFlow` | Dies on rotation |25| 10 | `Dispatchers.IO` around Room | `viewModelScope.launch` only | Double dispatch |26| 11 | `@Provides` interface bind | `@Binds` interface | Extra allocation |27| 12 | Nav arg = whole object | Nav arg = `id: String` | Process death crash |28| 13 | `fallbackToDestructiveMigration()` prod | Explicit `Migration` | Data wipe |29| 14 | `Modifier.clickable` before `clip` wrong order | padding→clip→bg→clickable | Wrong hit target |30| 15 | Sort inside `LazyColumn` items | `remember` or VM sort | Recompose every frame |31| 16 | `derivedStateOf` without `remember` | `remember { derivedStateOf { } }` | Recreated each frame |32| 17 | Backwards write in `@Composable` | Write in event handlers only | Infinite recompose |33| 18 | `!!` on nullable state | Smart cast / `when` | NPE |34| 19 | Ktor `HttpClient()` no engine | `HttpClient(OkHttp)` / `Darwin` | Runtime crash |35| 20 | Hardcode `compileSdk 34` new app | `compileSdk 35` + edge-to-edge | Play policy |36| 21 | `SharedPreferences.edit().apply()` | `dataStore.edit { }` suspend | Race + main-thread ANR risk |37| 22 | `collectAsLazyPagingItems()` in VM | `pager.flow.asState()` + presenter collect | Wrong layer + stale paging |38| 23 | Coil `AsyncImage` without network dep | `coil-compose` + `coil-network-okhttp` | Images never load |39| 24 | `contentDescription = null` on icons | Meaningful description or `null` only if decorative | TalkBack failure |40| 25 | `kapt` for Hilt/Room new project | KSP (`ksp(...)`) | Slow builds, K2 incompatibility |4142## How to use in review mode4344When auditing a file, grep for each WRONG column pattern. If found, cite row number and apply RIGHT fix before approving.4546Parent routing: [`../SKILL.md`](../SKILL.md) · Compose audit checklist: [`../skills/android-kotlin-compose/SKILL.md`](../skills/android-kotlin-compose/SKILL.md)47