INNER CODE UNIT · Java
stubMethod
anggrayudi/android-hidden-api · cli/Stubifier.java:87
private static void stubMethod(ClassNode cn, MethodNode mn) {
MethodInsnNode superCall = mn.name.equals("<init>") ? findSuperOrThisCall(cn, mn) : null;
if (mn.tryCatchBlocks != null) mn.tryCatchBlocks.clear();
if (mn.localVariables != null) mn.localVariables.clear();
if (mn.visibleLocalVariableAnnotations != null) mn.visibleLocalVariableAnnotations.clear();
if (mn.invisibleLocalVariableAnnotations != null) mn.invisibleLocalVariableAnnotations.clear();
InsnList body = new InsnList();
// A constructor must chain to super()/this() before returning, or the JVM verifier
// rejects the class ("Constructor must call super() or this() before return") once it is
// loaded — which is what happens to the *mockable* jar Gradle derives for unit tests.
// Re-issue the original super/this call with default arguments (all mocked classes have
// trivial ctors, so the values are never used), then fall through to the stub throw.
if (superCall != null) {
body.add(new VarInsnNode(Opcodes.ALOAD, 0)); // this
for (Type arg : Type.getArgumentTypes(superCall.desc)) {
body.add(defaultValue(arg));