Hi Kotlin team, I encountered a bug about regex &a...
# kotlin-native
p
Hi Kotlin team, I encountered a bug about regex & newSingleThreadContext on Kotlin/Native iOS, below is the core code snipped, it crash when call
regex.find
, and the stack has over 700 frames (please check the attached screenshot). It always crash, both on my iPhone11 real device and iPhone11 simulator.
Copy code
class Greeting {
    @OptIn(ExperimentalCoroutinesApi::class) fun greeting(): String {
        val scope = CoroutineScope(newSingleThreadContext("test"))
        scope.launch {
          val regex = """(.*?mainpic.*?src=")""".toRegex()
          val res = regex.find(TEST_HTML.replace("\n", ""))
          println("regex res: $res ${res?.groups?.size}")
        }

        return "Hello!"
    }

    private val TEST_HTML = "a specific html string"
}
It won’t crash if I change the code above a little bit: 1. not launch the coroutine in scope with
newSingleThreadContext
; 2. change the
regex
to other value; 3. change the
TEST_HTML
to other value (please find the full value of it in attached project, which is created using Android studio project wizard, and add code above);
m
Unfortunately I can't tell you what's wrong, however, I would recommend creating a new issue in youtrack if you suspect a bug. There it will get the appropriate attention.