Created
May 2, 2025 06:34
-
-
Save erudenko/c70e112acf46a81dadb8c6f73683c376 to your computer and use it in GitHub Desktop.
errorfile.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.os.Bundle | |
| import android.util.Log | |
| import androidx.appcompat.app.AppCompatActivity | |
| import kotlinx.coroutines.* | |
| class Repository { | |
| private var cache: MutableList<String>? = null | |
| fun addToCache(item: String) { | |
| cache!!.add(item) | |
| } | |
| suspend fun fetchAll(): List<String> = coroutineScope { | |
| return@coroutineScope cache!! | |
| } | |
| } | |
| class BuggyActivity : AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| runBlocking { heavyDbCall() } | |
| val ints = mutableListOf(1, 2, 3, 4, 5) | |
| for (v in ints) { | |
| if (v % 2 == 0) ints.remove(v) | |
| } | |
| startLeakyJob() | |
| varianceProblem() | |
| val b = Box<Int>() | |
| b.value = 42 | |
| } | |
| private fun varianceProblem() { | |
| val strings: Array<String> = arrayOf("a", "b") | |
| val anys: Array<Any> = strings | |
| anys[0] = 42 | |
| } | |
| private fun startLeakyJob() { | |
| GlobalScope.launch { | |
| delay(10_000) | |
| Log.d("Buggy", "done") | |
| } | |
| } | |
| private suspend fun heavyDbCall() { delay(5_000) } | |
| } | |
| class Box<out T> { | |
| var value: T? = null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment