Obfuscation causes VerifyError: Expecting a stackmap frame

crusam picture crusam · Nov 12, 2013 · Viewed 8.2k times · Source

We are using latest JDK 7 (u45) and ProGuard Version 4.10

Lately starting our distribution fails, after obfuscating it, with the following error:

Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at
branch target 155
Exception Details:
  Location:
    com/bla/bla/service/ioc/SpringBootstrap.c()V @0: getstatic
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: b200 73b6 008b 9900 82b2 0073 b800 933b
    0000010: 1a99 0074 b200 73b6 008d 9900 6bb2 0074
    0000020: 1221 b600 cfb8 0092 4c2b b600 9c12 1db9
    ...
  Exception Handler Table:
    bci [0, 152] => handler: 155

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I found several discussions about this topic on StackOverflow, like

From what I understood is, that java 7 uses a stricter verification and introduced a stack map for classes to verify the code. So somehow during my obfuscation process this map seems to get corrupted, since only this exception occurs, when I obfuscate my project with proguard.

Disabling the verification with -XX:-UseSplitVerifier and starting the builded jar helps, but im not really sure if that should be the way handling this issue.

So I wonder if anyone else had a simular error? Or if anyone might even knows a specific way to solve this, for example by adjusting the proguard konfiguration for the obfuscation process?

Answer

Eric Lafortune picture Eric Lafortune · Nov 12, 2013

I assume you are not specifying -dontpreverify? That option will almost certainly lead to these errors, since it will stop ProGuard from updating the StackMapTable attribute. The attribute was optional in Java 6, but it is required in Java 7.

You could still try a beta version of ProGuard 4.11, but it is unlikely that it makes a difference here. If you mail me the processed class file, I'll look into it.

(I am the developer of ProGuard)