Hello, I use this class in my tests: ```interface ...
# announcements
g
Hello, I use this class in my tests:
Copy code
interface 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:
Copy code
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?
j
just guessing based on the exception, if you can remove the
JvmStatic
annotation, does it fix it? Or change it from an expression to the
get
syntax?
val e: Nothing get() = throw Exception("")
alternatively any reason to not throw in the
init
block vs creating a member to throw?
Copy code
class Foo {
    companion object {
        init {
            throw Exception("foo")
        }
    }
}
g
Actually, I need @Jvmstatic as this is what I test: an exception into a static variable. But your question reminds me I could write directly a Java class
I'm wondering If I should fill an issue, as it may appear as a regression
👍 1
r
If in doubt, you might as well file one. The JB team can then decide if it's a regression or not.
a
I believe this is https://youtrack.jetbrains.com/issue/KT-46568 which is fixed in the upcoming Kotlin 1.5.10.
👍 2