private void injectHandleThrowable()

in TransformCore/src/main/java/com/facebook/ads/injkit/crashshield/CrashShieldInjector.java [288:333]


  private void injectHandleThrowable(ClassNode cls, MethodNode method) {

    LabelNode tryNode = new LabelNode();
    LabelNode catchNode = new LabelNode();

    AbstractInsnNode firstCoveredInstruction;

    try {
      firstCoveredInstruction = findFirstCoveredInstruction(cls, method);
    } catch (AnnotationProcessingException t) {
      return;
    }

    if (firstCoveredInstruction != null) {

      method.instructions.insertBefore(firstCoveredInstruction, tryNode);

      if (!AsmMethodUtils.isConstructor(method)) {
        insertIfCrashingCondition(cls, method);
      }

      method.instructions.add(catchNode);

      if ((method.access & Opcodes.ACC_STATIC) != 0) {
        method.instructions.add(new LdcInsnNode(Type.getObjectType(cls.name)));
      } else {
        method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
      }

      method.instructions.add(
          new MethodInsnNode(
              Opcodes.INVOKESTATIC,
              exceptionHandlerIName,
              "handleThrowable",
              "(Ljava/lang/Throwable;Ljava/lang/Object;)V",
              false));
      method.instructions.add(makeReturnCodeFor(method));

      if (method.tryCatchBlocks == null) {
        method.tryCatchBlocks = new ArrayList<>();
      }

      method.tryCatchBlocks.add(
          new TryCatchBlockNode(tryNode, catchNode, catchNode, "java/lang/Throwable"));
    }
  }