https://kotlinlang.org logo
#announcements
Title
# announcements
j

Joe

07/17/2019, 5:30 PM
Having a question with respect to using the
?:
elvis operator to provide a default: If I have reasonable tests around code that does something like:
Copy code
val x = nullableObject?.method() ?: default
JaCoCo tells me I have one of 4 branches uncovered. If I change that to:
Copy code
val nullableX = nullableObject?.method()
    val x = nullableX ?: default
JaCoCo tells me all branches are covered (2 branches per line). I'm guessing the "uncovered" branch is when
nullableObject
is non-null, but
method()
returns null -- is there a way to get JaCoCo to realize that branch is not possible based on
method()
not being nullable? Or is there a better practice here?
e

elizarov

07/17/2019, 6:37 PM
Hold on. It is actually inefficient in Kotlin JVM BE. I’ll report it.
j

Joe

07/17/2019, 6:59 PM
cool, thanks!
3 Views