private AbstractInsnNode findFirstCoveredInstruction()

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


  private AbstractInsnNode findFirstCoveredInstruction(ClassNode clsNode, MethodNode method)
      throws AnnotationProcessingException {
    if (!AsmMethodUtils.isConstructor(method)) {
      return method.instructions.getFirst();
    }

    AbstractInsnNode superOrThisInit = null;
    for (Iterator<AbstractInsnNode> it = method.instructions.iterator(); it.hasNext(); ) {
      AbstractInsnNode current = it.next();
      if (current.getOpcode() == Opcodes.INVOKESPECIAL) {
        if (((MethodInsnNode) current).owner.equals(clsNode.superName)
            || ((MethodInsnNode) current).owner.equals(clsNode.name)) {
          if (superOrThisInit != null) {
            // This may actually happen in legal code, but it is really difficult to
            // support (I think). And so far doesn't occur in our codebase.
            throw new AnnotationProcessingException(
                String.format(
                    Locale.US,
                    "Class '%s', constructor '%s' has more than one "
                        + "INVOKESPECIAL for this or superclass",
                    clsNode.name,
                    method.desc));
          }

          superOrThisInit = current;
        }
      }
    }

    if (superOrThisInit == null) {
      // Super class must always be constructed.
      throw new AssertionError();
    }

    return superOrThisInit.getNext();
  }