public static List<TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction(InsnList insnList,List<TryCatchBlockNode> tryCatchBlockNodes,AbstractInsnNode insnNode){
  Validate.notNull(insnList);
  Validate.notNull(tryCatchBlockNodes);
  Validate.notNull(insnNode);
  Validate.noNullElements(tryCatchBlockNodes);
  Map<LabelNode,Integer> labelPositions=new HashMap<>();
  int insnNodeIdx=-1;
  ListIterator<AbstractInsnNode> insnIt=insnList.iterator();
  int insnCounter=0;
  while (insnIt.hasNext()) {
    AbstractInsnNode node=insnIt.next();
    if (node == insnNode) {
      if (insnNodeIdx == -1) {
        insnNodeIdx=insnCounter;
      }
 else {
        throw new IllegalArgumentException();
      }
    }
    if (node instanceof LabelNode) {
      labelPositions.put((LabelNode)node,insnCounter);
    }
    insnCounter++;
  }
  Validate.isTrue(insnNodeIdx != -1);
  List<TryCatchBlockNode> ret=new ArrayList<>();
  for (  TryCatchBlockNode tryCatchBlockNode : tryCatchBlockNodes) {
    Integer startIdx=labelPositions.get(tryCatchBlockNode.start);
    Integer endIdx=labelPositions.get(tryCatchBlockNode.end);
    Validate.isTrue(startIdx != null);
    Validate.isTrue(endIdx != null);
    if (insnNodeIdx >= startIdx && insnNodeIdx < endIdx) {
      ret.add(tryCatchBlockNode);
    }
  }
  return ret;
}

public static List < TryCatchBlockNode > findTryCatchBlockNodesEncompassingInstruction ( InsnList insnList , List < TryCatchBlockNode > tryCatchBlockNodes , AbstractInsnNode insnNode ) { Validate . notNull ( insnList ) ; Validate . notNull ( tryCatchBlockNodes ) ; Validate . notNull ( insnNode ) ; Validate . noNullElements ( tryCatchBlockNodes ) ; Map < LabelNode , Integer > labelPositions = new HashMap < > ( ) ; int insnNodeIdx = - 1 ; ListIterator < AbstractInsnNode > insnIt = insnList . iterator ( ) ; int insnCounter = 0 ; while ( insnIt . hasNext ( ) ) { AbstractInsnNode node = insnIt . next ( ) ; if ( node == insnNode ) { if ( insnNodeIdx == - 1 ) { insnNodeIdx = insnCounter ; } else { throw new IllegalArgumentException ( ) ; } } if ( node instanceof LabelNode ) { labelPositions . put ( ( LabelNode ) node , insnCounter ) ; } insnCounter ++ ; } Validate . isTrue ( insnNodeIdx != - 1 ) ; List < TryCatchBlockNode > ret = new ArrayList < > ( ) ; for ( TryCatchBlockNode tryCatchBlockNode : tryCatchBlockNodes ) { Integer startIdx = labelPositions . get ( tryCatchBlockNode . start ) ; Integer endIdx = labelPositions . get ( tryCatchBlockNode . end ) ; Validate . isTrue ( startIdx != null ) ; Validate . isTrue ( endIdx != null ) ; if ( insnNodeIdx >= startIdx && insnNodeIdx < endIdx ) { ret . add ( tryCatchBlockNode ) ; } } return ret ; }
find trycatch blocks within a method that an instruction is apart of . only includes the try portion , not the catch ( handler ) portion .
