NPE in `ExpressionCodegen.generate`
See original GitHub issueDescribe the bug When trying to integrate kotlinx.serialization, unable to compile.
e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
File being compiled: /home/malachid/work/poc/src/main/kotlin/TestData.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:239)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:142)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm$default(JvmBackendFacade.kt:108)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFiles(JvmBackendFacade.kt:95)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:40)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:616)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:203)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:346)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:240)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:81)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:601)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1633)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Exception while generating code for:
CONSTRUCTOR visibility:public <> (seen1:kotlin.Int, thing:kotlin.Int?, serializationConstructorMarker:kotlinx.serialization.internal.SerializationConstructorMarker?) returnType:<root>.TestData
annotations:
Deprecated(message = 'This synthesized declaration should not be used directly', replaceWith = ReplaceWith(expression = '', imports = []), level = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:HIDDEN' type=kotlin.DeprecationLevel)
VALUE_PARAMETER name:seen1 index:0 type:kotlin.Int
VALUE_PARAMETER name:thing index:1 type:kotlin.Int?
VALUE_PARAMETER name:serializationConstructorMarker index:2 type:kotlinx.serialization.internal.SerializationConstructorMarker?
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethodNode(ClassCodegen.kt:268)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethod(ClassCodegen.kt:285)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generate(ClassCodegen.kt:123)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:139)
... 37 more
Caused by: java.lang.NullPointerException
at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.generate(ExpressionCodegen.kt:199)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.doGenerate(FunctionCodegen.kt:105)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:48)
... 41 more
FAILURE: Build failed with an exception.
To Reproduce
- copy this template https://github.com/JetBrains/compose-jb/tree/master/templates/desktop-template
- add
kotlin("plugin.serialization") version "1.4.10"
- add
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
- add a very basic model into
src/main/kotlin
:
import kotlinx.serialization.*
@Serializable
data class TestData(var thing: Int? = null)
(I have tested w/ and w/o the default value; with var and val)
Expected behavior
App should compile.
As a side note, you have to include json support - even if that isn’t the intended target; or the IDE can’t resolve @Serializable
.
Environment
- Kotlin version: 1.4.10
- Library version: 1.4.10 and 1.0.1
- Kotlin platforms: JVM
- Gradle version: 6.5.1
- IDE version (if bug is related to the IDE) IntelliJ Ultimate 2020.3 EAP --or-- pure CLI
- Other relevant context: Ubuntu 18.04, JDK 11
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top Results From Across the Web
NPE in ExpressionCodegen.intermediateValueForProperty with ...
NPE in ExpressionCodegen.intermediateValueForProperty with accessing private field of companion object in private inline function of inline class.
Read more >NPE in the IDE - Kotlin Discussions
CompileSession.generate(CompileSession.java:161) at org.jetbrains.jet.compiler. ... genQualified(ExpressionCodegen.java:156) at org.jetbrains.jet.codegen.
Read more >New RexNode-to-Expression CodeGen Implementation
As illustrated in CALCITE-3173, when this cooperation is broken in some special cases, it will cause exceptions like NPE, such as CALCITE-3142, CALCITE-3143 ......
Read more >[jira] [Resolved] (CALCITE-3224) New RexNode-to-Expression ...
[jira] [Resolved] (CALCITE-3224) New RexNode-to-Expression CodeGen ... it will > cause exceptions like NPE, such as CALCITE-3142, CALCITE-3143, CALCITE-3150 ...
Read more >IllegalArgumentException or NullPointerException for a null ...
The following answers to this question make persuasive arguments that NullPointerException is the correct exception: stackoverflow.com/a/8160/372926 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve currently encountered the same issue for a
sealed class
’s child which uses the@Serializable
annotation: Stacktrace GistThe implementation was working before when I was purely using Kotlin Platform Mobile (along with Jetpack Compose for Android), but it started failing once I introduced Jetbrains Compose for Desktop (along with its modifications for
:common
’sbuild.gradle.kts
file).Is there a timeline on when compatibility for these two might be introduced?
I’m getting this error only on incremental compilation (clean builds work fine) in a Kotlin-only module on Android Studio and I’m not using Jetpack Compose. Any ideas on what could be causing this?