Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProGuard optimization causes "java.lang.VerifyError: Bad type on operand stack" #2719

Closed
wtlgo opened this issue Jun 17, 2024 · 6 comments
Closed
Assignees
Labels

Comments

@wtlgo
Copy link

wtlgo commented Jun 17, 2024

Describe the bug

If I try to optimize the application by disabling

# -dontoptimize

I get the following error:

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    dev/mikchan/misc/ksp/model/Model$$serializer.<clinit>()V @38: putstatic
  Reason:
    Type 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/descriptors/SerialDescriptor' (current frame, stack[0]) is not assignable to 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/internal/PluginGeneratedSerialDescriptor'
  Current Frame:
    bci: @38
    flags: { }
    locals: { 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/internal/PluginGeneratedSerialDescriptor' }
    stack: { 'dev/mikchan/misc/ksp/shadow/kotlinx/serialization/descriptors/SerialDescriptor' }
  Bytecode:
    0000000: bb00 0759 b700 18b3 0014 bb00 1059 1202
    0000010: b200 14c0 000f 04b7 001b 594b 1203 03b6
    0000020: 001c 2ac0 000c b300 15b1               

	at dev.mikchan.misc.ksp.model.Model$Companion.serializer(Model.kt:5)
	at dev.mikchan.misc.ksp.MainKt.main(Main.kt:1014)

Process finished with exit code 1

If I disable the optimization, though, everything works OK.

To Reproduce

Here's a project with reproduction: https://github.com/wtlgo/Kotlin-Serialization-Proguard

Expected behavior

It should work correctly either with or without optimization

Environment

  • Kotlin version: 2.0.0
  • Library version: 1.7.0
  • Kotlin platforms: JVM
  • Gradle version: 8.5
  • IDE version (if bug is related to the IDE): It isn't related, but it's IntelliJ IDEA 2024.1.2 (Ultimate Edition)
  • Other relevant context: Windows 10, com.guardsquare:proguard-gradle:7.5.0
@buehlerjochen
Copy link

We have exactly the same issue in our project. Any updates on this?

@shanshin
Copy link
Contributor

Hi, we will try to investigate this problem soon

@shanshin
Copy link
Contributor

@buehlerjochen, @wtlgo
try to add this rule to your ProGuard rules file

-keepclassmembers public class **$$serializer {
    private ** descriptor;
}

@shanshin
Copy link
Contributor

Related issue in ProGuard Guardsquare/proguard#415

shanshin added a commit that referenced this issue Jun 25, 2024
Disabled optimisation for descriptor field because in some versions of ProGuard, optimization generates incorrect bytecode that causes a verification error.

Fixes #2719
@buehlerjochen
Copy link

@shanshin Sorry for the late response, Just tested you proposal and it seems to solve the issue. Thank you very much!

@wtlgo
Copy link
Author

wtlgo commented Jun 28, 2024

Yeah, works for me too. Thank you!
I'm going to remove my reproduction repo, here's a zip of it for archive purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants