Hello! I'm not certain if this is the right place ...
# compiler
v
Hello! I'm not certain if this is the right place to ask, so please feel free to direct me to the correct channel if needed. I've recently migrated our Android application from Kotlin 1.9.22 to 2.0.20 and noticed a difference in how the two Kotlin versions handle the same code:
Copy code
// Java class
public class CrashProvider {
    String returnNullString() {
        return null;
    }
}

// Kotlin class
private fun returnNotNullString1(): String {   // returns null in Kotlin 2.0.20
    return try {
        CrashProvider().returnNullString()
    } catch (e: Exception) {
        ""
    }
}

private fun returnNotNullString2(): String {
    return CrashProvider().returnNullString()
}

fun main() {
    val string1 = returnNotNullString1() // returns "" in Kotlin 1.9.22 and null in Kotlin 2.0.20
    val string2 = returnNotNullString2() // crashed in both versions what is expected behaviour
}
👀 1
p
Looks like a bug. Better to post reproducing example on Github and create an issue in YouTrack with link to reproducer.
👍🏻 1
v
Found the issue in YouTrack. Probably will be fixed in Kotlin 2.1.0
👍 1