Hi, I got warning `Inappropriate blocking method c...
# coroutines
k
Hi, I got warning
Inappropriate blocking method call
when call blocking method in suspend function. I don't know that why this code was warned... How to fix this?
Copy code
import java.net.URL

suspend fun foo(bar: String): String {
    if (bar.isEmpty()) {
        return ""
    }
    return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
        // warning: Inappropriate blocking method call
        URL("<https://www.example.com>")
            .readText()
    }
}
o
it seems fine, I believe this is an intellij bug but I can't find an exact issue that looks the same
1
you might want to file one yourself
Nope… no that one
Actually, cannot reproduce. Works fine for me.
If I remove
withContext
it complains on
URL
which is a bug: https://youtrack.jetbrains.com/issue/KT-39352
But it does not complain on `readText`: https://youtrack.jetbrains.com/issue/KT-39476
l
Where is that list of blocking methods?
e
There’s no like. It consider any Java method that
throws IOException
to be potentially blocking (which is quite a good heuristic for Java world)
👍 3
And it is not really a coroutine-inspection. It is quite complicated beast that understands “non blocking reactive contexts” and warn on potential blocking code usage in them
k
Thank you. I understood. I will ignore this warning using
@Suppress
annotation.
e
I had the same issue using Jsoup's `get()`which I suppressed.
Copy code
val doc = Jsoup.connect(workUrl).get()
...triggers the same warning.