The following extension method does not result in ...
# announcements
d
The following extension method does not result in any errors in IntelliJ, however the complier gives a stacktrace. kotlinVersion = '1.2.41'
Copy code
inline fun <reified T> Klaxon.parseArrayOr(json: String, defaultValue: List<T>?): List<T>? = try {
    parseArray(json) ?: defaultValue
} catch (ignored: Exception) {
    defaultValue
}
Copy code
Cause: Not generated
Cause: String index out of range: -3
File being compiled at position: (91,22) in /Users/xxx/dev/xxx/xxx-xxx-xxx/src/test/kotlin/com/xxx/service/helpers/MockFactory.kt
The root cause was thrown at: String.java:1967
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:124)
        ...
        ...
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -3
        at java.lang.String.substring(String.java:1967)
        at org.jetbrains.kotlin.codegen.inline.SMAPParser.parse(SMAPParser.kt:58)
        at org.jetbrains.kotlin.codegen.inline.SMAPParser.parseOrCreateDefault(SMAPParser.kt:24)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.getMethodNode(inlineCodegenUtils.kt:142)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.doCreateMethodNodeFromCompiled(InlineCodegen.kt:549)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.createInlineMethodNode$backend(InlineCodegen.kt:507)
        at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:157)
Any ideas what I did wrong?