https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

Kirill Gribov

05/21/2021, 5:14 PM
Ok, we found the issue, it is easy to reproduce with simple code snippet -
Copy code
@JvmInline
value class ValueClassId(private val value: UUID)

class SomeService {

    suspend fun outerFails(id: UUID): ValueClassId {
        return inner(id)
    }

    suspend fun outerWorks(id: UUID) = try {
        somethingTrowing()
        justValueId(id)
    } catch (e: RuntimeException) {
        fallbackValueId(id)
    }

    private suspend fun inner(id: UUID) = try {
        somethingTrowing()
        justValueId(id)
    } catch (e: RuntimeException) {
        fallbackValueId(id)
    }

    private suspend fun justValueId(id: UUID): ValueClassId {
        delay(1)
        return ValueClassId(id)
    }

    private suspend fun fallbackValueId(id: UUID): ValueClassId {
        delay(1)
        return ValueClassId(id)
    }

    private suspend fun somethingTrowing(): Unit {
        delay(1)
        throw IllegalArgumentException()
    }
}

fun main(): Unit = runBlocking {
    val s = SomeService()
    val id = UUID.randomUUID()

    // works fine
    s.outerWorks(id)

    // Fails on: ContinuationImpl.kt:33
    // val outcome = invokeSuspend(param)
    // if (outcome === COROUTINE_SUSPENDED) return
    s.outerFails(id)
}
youtrack 1
should we create a bug on kotlin's YouTrack?
w

wasyl

05/21/2021, 5:43 PM
Always a good idea 🙂 At worst, it’ll get marked as duplicate and you’ll know which bug to track
k

Kirill Gribov

05/21/2021, 6:14 PM
n

Namig Tahmazli

05/21/2021, 6:44 PM
As far as I know value classes are designed to be wrapper around primitive types. In your case you have UUID which is not primitive type.
k

Kirill Gribov

05/21/2021, 6:45 PM
you can change UUID in my example on String and you will face same issue -
Copy code
class kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to class java.lang.String
i

Ilmir Usmanov [JB]

05/21/2021, 11:33 PM
Thanks! I cannot reproduce on current master. It is likely, that the issue is fixed in the upcoming 1.5.10 release. Will check, whether it is fixed in 1.5.10, though.
👌 1
k

Kirill Gribov

05/22/2021, 1:23 PM
@Ilmir Usmanov [JB] do you have any ETA when 1.5.10 will be released? or at least some RC version
1
9 Views