proguard-core icon indicating copy to clipboard operation
proguard-core copied to clipboard

MethodHandles / VarHandles Support

Open burningtnt opened this issue 1 year ago • 2 comments

The signature of MethodHandle and VarHandle directly use the argument type.

https://github.com/Guardsquare/proguard-core/blob/master/base/src/main/java/proguard/classfile/LibraryClass.java#L326 So the codes here cannot find the ref to MethodHandle and VarHandle and their signature cannot be changed when obfuscating jar with proguard.

burningtnt avatar Dec 02 '24 11:12 burningtnt

Hello @burningtnt,

Thank you for getting in touch with us.

Is it possible to provide a minimal reproducing sample project that triggers the issue when it is obfuscated with ProGuard? If you do have such a sample, please also state:

  1. Expected behavior
  2. Actual behavior

tvoc-gs avatar Dec 03 '24 11:12 tvoc-gs

What you need is to create these two classes:

public class Main {
    public static void main(String[] args) {
        MethodHandles.lookup().findVirtual(Hello.class, "hello", MethodType.methodType(void.class)).invokeExact(new Hello());
    }
}
public class Hello {
    public void hello() {
        System.out.println("Hello World");
    }
}

And configure ProGuard as 'obfuscate classes name, but don't shrink methods and their names.' DO REMEBER TO ENABLE -dontwarn java.lang.invoke.MethodHandle

The expected behavior is outputing a "Hello World". However, the actural behavior is thrown a ClassNotFound for Hello class, as the signature of invokeExact is (LHello;)V instead of something like L(LA;)v

You can simply search -dontwarn java.lang.invoke.MethodHandle on GitHub: https://github.com/search?q=%22-dontwarn+java.lang.invoke.MethodHandle%22&type=code to see a lot of problems.

burningtnt avatar Dec 04 '24 13:12 burningtnt