stacktrace-decoroutinator icon indicating copy to clipboard operation
stacktrace-decoroutinator copied to clipboard

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

Open languitar opened this issue 1 year ago • 7 comments

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.

languitar avatar Sep 30 '24 12:09 languitar

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

Anamorphosee avatar Sep 30 '24 12:09 Anamorphosee

Gradle Plugin targeting JVM

languitar avatar Sep 30 '24 12:09 languitar

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)

Anamorphosee avatar Sep 30 '24 13:09 Anamorphosee

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?

languitar avatar Sep 30 '24 15:09 languitar

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

Anamorphosee avatar Sep 30 '24 15:09 Anamorphosee

@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.) ?

Anamorphosee avatar Oct 20 '24 14:10 Anamorphosee

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 avatar Oct 20 '24 17:10 languitar

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:

  • We use jacoco for coverage
  • On my system, this happens with temurin 17 as the JDK
  • Gradle version 8

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)
}

languitar avatar Nov 07 '24 08:11 languitar

I'm not sure, if this issue is related. I also got Bad type on operand stack. Distilled an example here

AramMessdaghi9001 avatar Mar 20 '25 15:03 AramMessdaghi9001

@AramMessdaghi9001 Thank you for the example. It really helped to determine the issue. The cause of the bug is that Kotlin compiler produces incorrect byte code for inline functions transformed for Decoroutinator. The issue will be fixed in the next Decoroutinator release. So far you can add the temporary fix or use Decoroutinator as JVM agent (the ways 2. and 3. in readme).

Anamorphosee avatar Mar 22 '25 15:03 Anamorphosee

Thank you, this seems to fix this issue. I found another one though. Will create a bug

AramMessdaghi9001 avatar Apr 23 '25 12:04 AramMessdaghi9001

fixed at 2.4.9

Anamorphosee avatar Apr 23 '25 18:04 Anamorphosee