Program: 99842
Project: 99842
Buggy source:
/** 
 * Return a view of the   {@link ControlFlowGraph} for an {@link IR}, which elides all exceptional exits from PEIs in the IR.
 */
public static Graph<ISSABasicBlock> sanitize(IR ir,IClassHierarchy cha) throws IllegalArgumentException, WalaException {
  if (ir == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  ControlFlowGraph<SSAInstruction,ISSABasicBlock> cfg=ir.getControlFlowGraph();
  Graph<ISSABasicBlock> g=SlowSparseNumberedGraph.make();
  for (Iterator<? extends ISSABasicBlock> it=cfg.iterator(); it.hasNext(); ) {
    g.addNode(it.next());
  }
  for (Iterator it=cfg.iterator(); it.hasNext(); ) {
    ISSABasicBlock b=(ISSABasicBlock)it.next();
    for (Iterator it2=cfg.getSuccNodes(b); it2.hasNext(); ) {
      ISSABasicBlock b2=(ISSABasicBlock)it2.next();
      if (!b2.isExitBlock()) {
        g.addEdge(b,b2);
      }
    }
  }
  ISSABasicBlock exit=cfg.exit();
  for (Iterator it=cfg.getPredNodes(exit); it.hasNext(); ) {
    ISSABasicBlock b=(ISSABasicBlock)it.next();
    SSAInstruction s=ir.getInstructions()[b.getLastInstructionIndex()];
    if (s == null) {
      continue;
    }
    if (s instanceof SSAReturnInstruction || s instanceof SSAThrowInstruction) {
      g.addEdge(b,exit);
    }
 else {
      TypeReference[] exceptions=null;
      try {
        exceptions=computeExceptions(cha,ir,s);
      }
 catch (      InvalidClassFileException e1) {
        e1.printStackTrace();
        Assertions.UNREACHABLE();
      }
      for (Iterator it2=cfg.getSuccNodes(b); it2.hasNext(); ) {
        IBasicBlock c=(IBasicBlock)it2.next();
        if (c.isCatchBlock()) {
          SSACFG.ExceptionHandlerBasicBlock cb=(ExceptionHandlerBasicBlock)c;
          for (Iterator it3=cb.getCaughtExceptionTypes(); it3.hasNext(); ) {
            TypeReference ex=(TypeReference)it3.next();
            IClass exClass=cha.lookupClass(ex);
            if (exClass == null) {
              throw new WalaException("String_Node_Str" + ex);
            }
            for (int i=0; i < exceptions.length; i++) {
              if (exceptions[i] != null) {
                IClass exi=cha.lookupClass(exceptions[i]);
                if (exi == null) {
                  throw new WalaException("String_Node_Str" + exceptions[i]);
                }
                if (cha.isSubclassOf(exi,exClass)) {
                  exceptions[i]=null;
                }
              }
            }
          }
        }
      }
      TypeReference[] declared=null;
      try {
        declared=ir.getMethod().getDeclaredExceptions();
      }
 catch (      InvalidClassFileException e) {
        e.printStackTrace();
        Assertions.UNREACHABLE();
      }
      if (declared != null && exceptions != null) {
        for (int i=0; i < exceptions.length; i++) {
          boolean isDeclared=false;
          if (exceptions[i] != null) {
            IClass exi=cha.lookupClass(exceptions[i]);
            if (exi == null) {
              throw new WalaException("String_Node_Str" + exceptions[i]);
            }
            for (int j=0; j < declared.length; j++) {
              IClass dc=cha.lookupClass(declared[j]);
              if (dc == null) {
                throw new WalaException("String_Node_Str" + declared[j]);
              }
              if (cha.isSubclassOf(exi,dc)) {
                isDeclared=true;
                break;
              }
            }
            if (isDeclared) {
              g.addEdge(b,exit);
            }
          }
        }
      }
    }
  }
  return g;
}

Fixed version (ground truth):
/** 
 * Return a view of the   {@link ControlFlowGraph} for an {@link IR}, which elides all exceptional exits from PEIs in the IR.
 */
public static Graph<ISSABasicBlock> sanitize(IR ir,IClassHierarchy cha) throws IllegalArgumentException, WalaException {
  if (ir == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  ControlFlowGraph<SSAInstruction,ISSABasicBlock> cfg=ir.getControlFlowGraph();
  Graph<ISSABasicBlock> g=SlowSparseNumberedGraph.make();
  for (Iterator<? extends ISSABasicBlock> it=cfg.iterator(); it.hasNext(); ) {
    g.addNode(it.next());
  }
  for (Iterator it=cfg.iterator(); it.hasNext(); ) {
    ISSABasicBlock b=(ISSABasicBlock)it.next();
    for (Iterator it2=cfg.getSuccNodes(b); it2.hasNext(); ) {
      ISSABasicBlock b2=(ISSABasicBlock)it2.next();
      if (!b2.isExitBlock()) {
        g.addEdge(b,b2);
      }
    }
  }
  ISSABasicBlock exit=cfg.exit();
  for (Iterator it=cfg.getPredNodes(exit); it.hasNext(); ) {
    ISSABasicBlock b=(ISSABasicBlock)it.next();
    SSAInstruction s=ir.getInstructions()[b.getLastInstructionIndex()];
    if (s == null) {
      continue;
    }
    if (s instanceof SSAReturnInstruction || s instanceof SSAThrowInstruction || cfg.getSuccNodeCount(b) == 1) {
      g.addEdge(b,exit);
    }
 else {
      TypeReference[] exceptions=null;
      try {
        exceptions=computeExceptions(cha,ir,s);
      }
 catch (      InvalidClassFileException e1) {
        e1.printStackTrace();
        Assertions.UNREACHABLE();
      }
      for (Iterator it2=cfg.getSuccNodes(b); it2.hasNext(); ) {
        IBasicBlock c=(IBasicBlock)it2.next();
        if (c.isCatchBlock()) {
          SSACFG.ExceptionHandlerBasicBlock cb=(ExceptionHandlerBasicBlock)c;
          for (Iterator it3=cb.getCaughtExceptionTypes(); it3.hasNext(); ) {
            TypeReference ex=(TypeReference)it3.next();
            IClass exClass=cha.lookupClass(ex);
            if (exClass == null) {
              throw new WalaException("String_Node_Str" + ex);
            }
            for (int i=0; i < exceptions.length; i++) {
              if (exceptions[i] != null) {
                IClass exi=cha.lookupClass(exceptions[i]);
                if (exi == null) {
                  throw new WalaException("String_Node_Str" + exceptions[i]);
                }
                if (cha.isSubclassOf(exi,exClass)) {
                  exceptions[i]=null;
                }
              }
            }
          }
        }
      }
      TypeReference[] declared=null;
      try {
        declared=ir.getMethod().getDeclaredExceptions();
      }
 catch (      InvalidClassFileException e) {
        e.printStackTrace();
        Assertions.UNREACHABLE();
      }
      if (declared != null && exceptions != null) {
        for (int i=0; i < exceptions.length; i++) {
          boolean isDeclared=false;
          if (exceptions[i] != null) {
            IClass exi=cha.lookupClass(exceptions[i]);
            if (exi == null) {
              throw new WalaException("String_Node_Str" + exceptions[i]);
            }
            for (int j=0; j < declared.length; j++) {
              IClass dc=cha.lookupClass(declared[j]);
              if (dc == null) {
                throw new WalaException("String_Node_Str" + declared[j]);
              }
              if (cha.isSubclassOf(exi,dc)) {
                isDeclared=true;
                break;
              }
            }
            if (isDeclared) {
              g.addEdge(b,exit);
            }
          }
        }
      }
    }
  }
  return g;
}