Miha-x64 / Mikes_IDEA_extensions

IntelliJ IDEA: missing parts.
Apache License 2.0
34 stars 7 forks source link

Possible bug about `Replace '!!' with '?: return'` : incorrect and turned on forever #17

Closed AndroidDeveloperLB closed 2 years ago

AndroidDeveloperLB commented 2 years ago

I don't know if this inspection is by this addon, but I got it recently. If it's not, please close this and I will write it on the Android issue tracker or IntelliJ .

image

There are 2 bugs for this inspection:

  1. It's always used, even when it's turned off (and it's turned off by default).
  2. It doesn't make sense, and can ruin the flow of the code.

Example is right in the inspection:

val number: Int? = 42
fun foo() {
    val a = number!! // Replace '!!' with '?: return'
    println(1 + a)
}

If we have "!!", it means that at this point, we expect it to be non-null. If we are wrong, we will have a crash that we should know about, and fix it.

Miha-x64 commented 2 years ago

Here it is: https://youtrack.jetbrains.com/issue/KTIJ-15635

AndroidDeveloperLB commented 2 years ago

Indeed it's this one, but it doesn't mention that whether it's enabled or not, it's still being used... You've found it faster than how long it took me to write it, probably... :)