Gilles Barbier
05/14/2021, 1:08 PMinterface TaskA
class TaskWithExceptionInInitializerError : Task(), TaskA {
companion object {
@JvmStatic
val e: Nothing = throw Exception("ExceptionInInitializerError")
}
}
Of course this task is written to trigger an Exception during instantiation. I had no issue with Kotlin 1.4.30, but with 1.5.0, it does not compile, with following error:
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during code generation
...
Caused by: java.lang.RuntimeException: Exception while generating code for:
FUN JVM_STATIC_WRAPPER name:getE visibility:public modality:FINAL <> () returnType:kotlin.Nothing
EXPRESSION_BODY
BLOCK type=kotlin.Nothing origin=null
CALL 'public final fun <get-e> (): kotlin.Nothing declared in io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion' type=kotlin.Nothing origin=null
$this: GET_FIELD 'FIELD FIELD_FOR_OBJECT_INSTANCE name:Companion type:io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion visibility:public [final,static]' type=io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion origin=null
CALL 'public final fun throwKotlinNothingValueException (): kotlin.Nothing declared in kotlin.jvm.internal.Intrinsics' type=kotlin.Nothing origin=null
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:54)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethodNode(ClassCodegen.kt:338)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethod(ClassCodegen.kt:353)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generate(ClassCodegen.kt:128)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.doGenerateFilesInternal(JvmIrCodegenFactory.kt:206)
... 35 more
Caused by: java.lang.AssertionError: IrCall expected inside JvmStatic wrapper:
FUN JVM_STATIC_WRAPPER name:getE visibility:public modality:FINAL <> () returnType:kotlin.Nothing
EXPRESSION_BODY
BLOCK type=kotlin.Nothing origin=null
CALL 'public final fun <get-e> (): kotlin.Nothing declared in io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion' type=kotlin.Nothing origin=null
$this: GET_FIELD 'FIELD FIELD_FOR_OBJECT_INSTANCE name:Companion type:io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion visibility:public [final,static]' type=io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion origin=null
CALL 'public final fun throwKotlinNothingValueException (): kotlin.Nothing declared in kotlin.jvm.internal.Intrinsics' type=kotlin.Nothing origin=null
at org.jetbrains.kotlin.backend.jvm.codegen.IrCodegenUtilsKt.isAccessorForDeprecatedJvmStaticProperty(irCodegenUtils.kt:364)
at org.jetbrains.kotlin.backend.jvm.codegen.IrCodegenUtilsKt.isDeprecatedFunction(irCodegenUtils.kt:348)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.calculateMethodFlags(FunctionCodegen.kt:184)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.doGenerate(FunctionCodegen.kt:59)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:52)
... 39 more
Any idea, how to avoid this?Justin Tullgren
05/14/2021, 2:15 PMJvmStatic
annotation, does it fix it? Or change it from an expression to the get
syntax?
val e: Nothing get() = throw Exception("")
Justin Tullgren
05/14/2021, 2:17 PMinit
block vs creating a member to throw?Justin Tullgren
05/14/2021, 2:19 PMclass Foo {
companion object {
init {
throw Exception("foo")
}
}
}
Gilles Barbier
05/14/2021, 2:38 PMGilles Barbier
05/14/2021, 2:40 PMRuckus
05/14/2021, 4:01 PMAlexey Belkov [JB]
05/14/2021, 5:03 PM