Anamorphosee / stacktrace-decoroutinator

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

Sporadic "Bad type on operand stack" errors when running tests #40

Open languitar opened 1 month ago

languitar commented 1 month ago

With the most recent release, things mostly work fine. But it seems that there is some (gradle build?) cache invalidation issue. Sometimes, tests can only be executed after a gradle clean. Otherwise, we see exceptions like the following one:

Bad type on operand stack
Exception Details:
  Location:
    redacted/path/SomeClass$linkFunctionVariant$suspendImpl$$inlined$fixedQuery$1.invokeSuspend(Ldev/reformator/stacktracedecoroutinator/provider/DecoroutinatorSpec;Ljava/lang/Object;)Ljava/lang/Object; @16: getfield
  Reason:
    Type 'dev/reformator/stacktracedecoroutinator/provider/DecoroutinatorSpec' (current frame, stack[0]) is not assignable to 'redacted/path/SomeClass$someMethod$suspendImpl$$inlined$fixedQuery$1'
  Current Frame:
    bci: @16
    flags: { }
    locals: { 'dev/reformator/stacktracedecoroutinator/provider/DecoroutinatorSpec', 'java/lang/Object', '[Z' }
    stack: { 'dev/reformator/stacktracedecoroutinator/provider/DecoroutinatorSpec' }
  Bytecode:
    0000000: redacted...
  Stackmap Table:
    append_frame(@36,Object[#222])
    append_frame(@64,Integer)
    full_frame(@104,{Object[#124],Object[#90],Object[#222],Integer},{Object[#142],Object[#124],Object[#90]})
    full_frame(@115,{Object[#124],Object[#90],Object[#222],Integer},{Object[#142],Object[#124],Object[#90]})
    full_frame(@126,{Object[#124],Object[#90],Object[#222],Integer},{Object[#142],Object[#124],Object[#90]})
    same_locals_1_stack_item_frame(@136,Object[#90])
    same_frame(@155)
    same_frame(@162)
    full_frame(@192,{Object[#124],Object[#90],Object[#222],Integer},{Object[#124],Object[#90]})
    full_frame(@205,{Object[#124],Object[#90],Object[#222],Integer},{Object[#124],Object[#90]})
    same_locals_1_stack_item_frame(@215,Object[#90])
    full_frame(@221,{Object[#124],Object[#90],Object[#222],Integer},{Object[#124],Object[#90]})
    same_frame(@227)
    chop_frame(@256,1)

Sorry for not being able to provide all details here.

Anamorphosee commented 1 month ago

@languitar do you use Decoroutinator via Gradle plugin? And what’s your platform, JVM or Android?

languitar commented 1 month ago

Gradle Plugin targeting JVM

Anamorphosee commented 1 month ago

Thank you for the report. I’ll try to reproduce the issue on this week. By the way, for JVM it’s possible to install Decoroutinator at runtime without relaying on Gradle(ways 2 or 3 from https://github.com/Anamorphosee/stacktrace-decoroutinator?tab=readme-ov-file#jvm)

languitar commented 1 month ago

Thank you for the report. I’ll try to reproduce the issue on this week. By the way, for JVM it’s possible to install Decoroutinator at runtime without relaying on Gradle(ways 2 or 3 from https://github.com/Anamorphosee/stacktrace-decoroutinator?tab=readme-ov-file#jvm)

The documentation sounded like the Gradle plugin being the preferred way. Is that still true?

Anamorphosee commented 1 month ago

Dynamic agent (way 2) probably will be banned by Oracle in JDK 22. Otherwise it doesn’t matter how Decoroutinator is installed.

Anamorphosee commented 4 weeks ago

@languitar I tried but couldn't reproduce the issue. Maybe you can provide a sample project with the issue? Or at least provide all of your build configuration (Gradle version, applied Gradle plugins, JDK version, etc.) ?

languitar commented 4 weeks ago

Unfortunately, I can't share the project and I'm also unable to reproduce this in an isolated sample. I'll try to collect the build facts tomorrow when I'm back at work.

languitar commented 1 week ago

Sorry, I missed this one.

The errors only sporadically appear when running tests from within IntelliJ as far as I can tell.

Some interesting pointers that might be related:

Here's our plugin definition block:

plugins {
    application
    kotlin("jvm")
    kotlin("plugin.serialization")
    alias(libs.plugins.gradle.node)
    id("tech.cariad.arche.common-repositories")
    jacoco
    id("jacoco-report-aggregation")
    `jvm-test-suite`
    id("test-report-aggregation")
    alias(libs.plugins.detekt)
    alias(libs.plugins.openapi.generator)
    // Recover stack traces in exceptions thrown in Kotlin coroutines to see better stack traces.
    alias(libs.plugins.stacktracedecoroutinator)
}