Inspectopedia Help

'inline fun' extension receiver can be explicitly nullable until Kotlin 1.2

Reports inline functions with non-nullable extension receivers which don't use the fact that extension receiver is not nullable.

Before Kotlin 1.2, calls of inline fun with flexible nullable extension receiver (a platform type with an unknown nullability) did not include nullability checks in bytecode. Since Kotlin 1.2, nullability checks are included into the bytecode (see KT-12899).

Thus functions which do not use the fact that extension receiver is not nullable are dangerous in Kotlin until 1.2 and it's recommended to make such functions to have nullable receiver.

Example:

inline fun String.greet() { println("Hello, $this!") } fun main() { // `System.getProperty` returns not denotable `String!` type val user = System.getProperty("user.name") user.greet() }

After the quick-fix is applied:

inline fun String.greet() { println("Hello, $this!") } fun main() { // `System.getProperty` returns not denotable `String!` type val user = System.getProperty("user.name") user.greet() }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

RedundantNotNullExtensionReceiverOfInline
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Java interop issues

This inspection only reports if the Kotlin language level of the project or module is lower than 1.2.

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Kotlin, 241.18072-IJ

Last modified: 18 June 2024