Anamorphosee / stacktrace-decoroutinator

Small lib for recovering stack trace in exceptions thrown in Kotlin coroutines
Apache License 2.0
202 stars 5 forks source link

IllegalStateException: "Different file names for class..." #15

Closed p4654545 closed 1 year ago

p4654545 commented 1 year ago

This is the exception: Caused by: java.lang.IllegalStateException: different file names for class [our-namespace.InterestProvider$createFlow$$inlined$transform$1]: [InterestProvider.kt] and [Emitters.kt] at dev.reformator.stacktracedecoroutinator.jvmagentcommon.DecoroutinatorJvmAgentStacktraceMethodHandleRegistry.getStacktraceMethodHandles$lambda-5(methodHandleRegistry-jvm-agent-common.kt:31)

It seems that Asm(?) has assigned "Emitters.kt" as the fileName of this particular ClassNode. As a result ClassNode.transform (classTransformer.kt) calls buildMarkerAnnotation with "Emitters.kt" as the filename, while clearly the filename should be InterestProvider.kt. The class "InterestProvider$createFlow$$inlined$transform$1" is generated inside InterestProvider.class. When decompiling InterestProvider.class I can see that the DebugMetaData information of "InterestProvider$createFlow$$inlined$transform$1" has the right filename: "InterestProvider.kt".

Adding "val filename: String" to DebugMetaDataInfo and replacing sourceFile in this line (classTransformer.kt):

visibleAnnotations.add(buildMarkerAnnotation(sourceFile, suspendFuncName2LineNumbers))

with

getDebugMetadataInfo()?.filename ?: sourceFile

results in Decoroutinator not complaining anymore when instrumenting our codebase.

Unfortunately I was not able to create a reproduction scenario and could not determine why Asm comes up with "Emitters.kt" as the source filename.

Anamorphosee commented 1 year ago

Hi, @p4654545 Thank you for your bug. It was reproduced for suspend crossinline function arguments. Fixed in version 2.3.4