Intellij and extension that implies not null

I face a problem with Intellij and extension function that implies not null on the receiver.

With this code snippet :

fun myFunction(myValue: String?) {
	when {
		myValue.isNullOrBlank() -> println("myValue is blank")
		else -> println(myValue.length)

Intellij complains on the line ‘println(myValue.length)’ (Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?) while it build without errors with maven (and in Intellij with Ctrl + F9).

It seems the IDE ignore the contract and implies instructions in the isNullOrBlank() extension and considers that the myValue variable might be null in the else branch.

Am I missing out on something?


Info :
- Intellij (2019.2.4)
- Kotlin 1.3.50

1 Like

I just tried that code in IntelliJ 2019.2.4, and it compiles and runs without warnings or errors.

I added a main function to test it:

fun main() {

I also don’t get any warnings. Make sure that your kotlin plugin is up to date. This wouldn’t effect compliation (because you are using maven), but is used for syntax highlithing and displaying warnings/errors in code.

1 Like

Thanks for your feedbacks.

I have the latest version of the kotlin plugin available for my Intellij (1.3.60-release-IJ2019.2-1).


The code runs correctly. It’s just annoying that the file is marked in red as if there is a problem …