Kotlin is not happy today... Is this a bug?
# android
s
Kotlin is not happy today... Is this a bug?
u
I don’t believe this is a bug, because
IOException
is traditionally thrown with failed blocking IO requests, the linter produces this warning. Because it is simply a warning, you are welcome to ignore assuming you know the risks of such a call, which I believe that in this case, there aren’t any real risks of blocking the current thread as
doStuff
should be executed in a different coroutine on a different thread (at least in theory a different thread)
e
https://youtrack.jetbrains.com/issue/KTIJ-15788 it's known that the current heuristic is pretty weak, but that's how it works
👍 2
s
Ok so the IDE assumes doStuff is a blocking function because it can throw
IOException
and shows the warning. So if I wrap it with try catch it should go away?
try catch didn't work in my code
e
won't work, it's still something "blocking" inside your suspend function whether it's wrapped or not
s
I'm concerned I'm doing something wrong, or blocking the coroutine.
Copy code
val json = String(e.response()?.errorBody()?.source()?.readByteArray() ?: byteArrayOf(), StandardCharsets.UTF_8)
readByteArray here shows the same warning. yep it throws IOException This line is the catching of HttpException from suspend retrofit call. I need to get the response body even if I don't get a 200 OK.
coroutine should not block anything..