Kotlin Coroutine Confidence: What's the IntelliJ IDEA inspection? (pg 133 & 141)

On page 133 in the callout text box, it says:

Did your IDE warn you about this misplaced Thread.sleep()? …

And on page 141 it says:

Have you been keeping an eye out for those IDE warnings? Tools like IntelliJ IDEA or Android Studio can identify the calls we’ve been making to Thread.sleep() and ImageIO.read(), and will let you know that you shouldn’t be using them in a suspending function. …

I’m not getting those warnings in IntelliJ IDEA, and I tend to keep my inspections configured pretty aggressively. And I don’t see them when I switch to the Default inspection profile. Can you tell me what inspection or inspections they are? (If you are not familiar with how to determine the name of the inspection generating a warning, let me know and I can respond with instructions.) Thanks!

Thanks! This was also recently pointed out to me by a reader in the Kotlin Slack group. What we discovered is that the warnings don’t currently work when the IDE’s K2 mode is turned on. There’s not much I can do about this, so I’m updating the text for the next Beta release to make it clear that many readers won’t see a warning at all. I hope the warning will be reintroduced in later IDE versions.

To answer your question, the specific inspection is Possibly blocking call in non-blocking context, under the JVM languages category.

Sorry for the confusion, and thank you for mentioning it!

You can find the previous Slack discussion about it here:

https://slack-chats.kotlinlang.org/t/27555859/in-kotlin-coroutine-confidence-u030s9809ph-off-the-cuff-says#4d83bb6b-a7de-4eaa-a86c-f3a1476e121c

1 Like