Inspectopedia Help

Possibly blocking call in non-blocking context

Reports thread-blocking method calls in code fragments where threads should not be blocked.

Example (Project Reactor):

Flux.just("1").flatMap(f -> { Flux<String> just = loadUsersFromDatabase(); just.toIterable(); // Error: blocking operator call in non-blocking scope return just; } );

Consider running blocking code with a proper scheduler, for example Schedulers.boundedElastic(), or try to find an alternative non-blocking API.

Example (Kotlin Coroutines):

suspend fun exampleFun() { Thread.sleep(100); // Error: blocking method call inside suspend function }

Consider running blocking code with a special dispatcher, for example Dispatchers.IO, or try to find an alternative non-blocking API.

Configure the inspection:

  • In the Blocking Annotations list, specify annotations that mark thread-blocking methods.

  • In the Non-Blocking Annotations list, specify annotations that mark non-blocking methods.

Specified annotations can be used as External Annotations

Inspection options

Here you can find the description of settings available for the Possibly blocking call in non-blocking context inspection, and the reference of their default values.

Consider unknown contexts blocking

Default: Selected

Consider Kotlin suspend context non-blocking

Default: Selected

Blocking annotations

[org.jetbrains.annotations.Blocking, io.micronaut.core.annotation.Blocking, io.smallrye.common.annotation.Blocking]

Non-blocking annotations

[org.jetbrains.annotations.NonBlocking, io.micronaut.core.annotation.NonBlocking, io.smallrye.common.annotation.NonBlocking]

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024