JavaObfuscatorTest
JavaObfuscatorTest copied to clipboard
Missing some tests for identifiers obfuscating
In Java 8 or better, see jls. We can construct a lambda based instance for interfaces.
package tech.skidonion.identifiersobfuscating;
import java.util.ArrayList;
import java.util.List;
public class LambdaTest {
interface SAMInterfaceA {
Object sam();
}
interface SAMInterfaceB {
List<?> sam();
}
interface SAMInterfaceC {
List<String> sam();
}
interface SAMInterfaceD {
ArrayList<String> sam();
}
public static void main(String[] args) {
System.out.println(((SAMInterfaceC & SAMInterfaceD & SAMInterfaceB & SAMInterfaceA) () -> new ArrayList<String>() {{
add("hello");
}}).sam());
}
}
In this case, SAMInterfaceA SAMInterfaceB SAMInterfaceC SAMInterfaceD don't point to the same single abstract method statically but dynamically.
When obfuscating, we should statically parse the generated invokedynamic bytecode to generate the correct mapping for all interfaces.
Therefore, it is necessary to add a test to test if that the mapping is correct.