ken_kentan
06/09/2020, 1:34 AMInappropriate blocking method call
when call blocking method in suspend function. I don't know that why this code was warned...
How to fix this?
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()
}
}
octylFractal
06/09/2020, 1:59 AMoctylFractal
06/09/2020, 1:59 AMelizarov
06/09/2020, 7:35 AMelizarov
06/09/2020, 7:36 AMelizarov
06/09/2020, 7:39 AMelizarov
06/09/2020, 7:40 AMwithContext
it complains on URL
which is a bug: https://youtrack.jetbrains.com/issue/KT-39352elizarov
06/09/2020, 7:48 AMlouiscad
06/09/2020, 7:49 AMelizarov
06/09/2020, 7:56 AMthrows IOException
to be potentially blocking (which is quite a good heuristic for Java world)elizarov
06/09/2020, 7:56 AMken_kentan
06/09/2020, 8:41 AM@Suppress
annotation.EyeCon
06/09/2020, 1:05 PMEyeCon
06/09/2020, 1:05 PMval doc = Jsoup.connect(workUrl).get()
...triggers the same warning.