Program: 88723
Project: 88723
Buggy source:
/** 
 * Method to compute the edges corresponding to exceptional control flow.
 * @param unitToDests A <tt>Map</tt> from {@link Unit}s to   {@link Collection}s of   {@link ExceptionalUnitGraph.ExceptionDest ExceptionDest}s which represent the handlers that might catch exceptions thrown by the <tt>Unit</tt>. This is an ``in parameter''.
 * @param unitToSuccs A <tt>Map</tt> from <tt>Unit</tt>s to {@link List}s of <tt>Unit</tt>s. This is an ``out parameter''; <tt>buildExceptionalEdges</tt> will add a mapping from every <tt>Unit</tt> in the body that may throw an exception that could be caught by a   {@link Trap} in the body to alist of its exceptional successors.
 * @param unitToPreds A <tt>Map</tt> from <tt>Unit</tt>s to <tt>List</tt>s of <tt>Unit</tt>s. This is an ``out parameter''; <tt>buildExceptionalEdges</tt> will add a mapping from each handler unit that may catch an exception to the list of <tt>Unit</tt>s whose exceptions it may catch.
 * @param omitExceptingUnitEdges Indicates whether to omitexceptional edges from excepting units which lack side effects
 * @return a {@link Set} of trap <tt>Unit</tt>s that might catch exceptions thrown by the first <tt>Unit</tt> in the  {@link Body}associated with the graph being constructed.  Such trap <tt>Unit</tt>s may need to be added to the list of heads (depending on your definition of heads), since they can be the first <tt>Unit</tt> in the <tt>Body</tt> which actually completes execution.
 */
protected Set buildExceptionalEdges(Map unitToDests,Map unitToSuccs,Map unitToPreds,boolean omitExceptingUnitEdges){
  Set trapsThatAreHeads=new ArraySet();
  for (Iterator it=unitToDests.entrySet().iterator(); it.hasNext(); ) {
    Map.Entry entry=(Map.Entry)it.next();
    Unit thrower=(Unit)entry.getKey();
    Collection dests=(Collection)entry.getValue();
    for (Iterator destIt=dests.iterator(); destIt.hasNext(); ) {
      ExceptionDest dest=(ExceptionDest)destIt.next();
      if (dest.trap() != null) {
        Unit catcher=dest.trap().getHandlerUnit();
        List throwersPreds=getUnexceptionalPredsOf(thrower);
        if (throwersPreds.size() == 0) {
          trapsThatAreHeads.add(catcher);
        }
 else {
          for (Iterator j=throwersPreds.iterator(); j.hasNext(); ) {
            Unit pred=(Unit)j.next();
            addEdge(unitToSuccs,unitToPreds,pred,catcher);
          }
        }
        if ((!omitExceptingUnitEdges) || thrower instanceof ThrowInst || thrower instanceof ThrowStmt|| mightHaveSideEffects(thrower)) {
          addEdge(unitToSuccs,unitToPreds,thrower,catcher);
        }
      }
    }
  }
class CFGEdge {
    Unit head;
    Unit tail;
    CFGEdge(    Unit head,    Unit tail){
      if (tail == null)       throw new RuntimeException("String_Node_Str" + head.toString() + ','+ tail.toString()+ ')');
      this.head=head;
      this.tail=tail;
    }
    public boolean equals(    Object rhs){
      if (rhs == this) {
        return true;
      }
      if (!(rhs instanceof CFGEdge)) {
        return false;
      }
      CFGEdge rhsEdge=(CFGEdge)rhs;
      return ((this.head == rhsEdge.head) && (this.tail == rhsEdge.tail));
    }
    public int hashCode(){
      int result=17;
      result=37 * result + this.head.hashCode();
      result=37 * result + this.tail.hashCode();
      return result;
    }
  }
  LinkedList workList=new LinkedList();
  for (Iterator trapIt=body.getTraps().iterator(); trapIt.hasNext(); ) {
    Trap trap=(Trap)trapIt.next();
    Unit handlerStart=trap.getHandlerUnit();
    if (mightThrowToIntraproceduralCatcher(handlerStart)) {
      List handlerPreds=getUnexceptionalPredsOf(handlerStart);
      for (Iterator it=handlerPreds.iterator(); it.hasNext(); ) {
        Unit pred=(Unit)it.next();
        workList.addLast(new CFGEdge(pred,handlerStart));
      }
      handlerPreds=getExceptionalPredsOf(handlerStart);
      for (Iterator it=handlerPreds.iterator(); it.hasNext(); ) {
        Unit pred=(Unit)it.next();
        workList.addLast(new CFGEdge(pred,handlerStart));
      }
      if (trapsThatAreHeads.contains(handlerStart)) {
        workList.addLast(new CFGEdge(null,handlerStart));
      }
    }
  }
  while (workList.size() > 0) {
    CFGEdge edgeToThrower=(CFGEdge)workList.removeFirst();
    Unit pred=edgeToThrower.head;
    Unit thrower=edgeToThrower.tail;
    Collection throwerDests=getExceptionDests(thrower);
    for (Iterator i=throwerDests.iterator(); i.hasNext(); ) {
      ExceptionDest dest=(ExceptionDest)i.next();
      if (dest.trap() != null) {
        Unit handlerStart=dest.trap().getHandlerUnit();
        boolean edgeAdded=false;
        if (pred == null) {
          if (!trapsThatAreHeads.contains(handlerStart)) {
            trapsThatAreHeads.add(handlerStart);
            edgeAdded=true;
          }
        }
 else {
          if (!getExceptionalSuccsOf(pred).contains(handlerStart)) {
            addEdge(unitToSuccs,unitToPreds,pred,handlerStart);
            edgeAdded=true;
          }
        }
        if (edgeAdded && mightThrowToIntraproceduralCatcher(handlerStart)) {
          workList.addLast(new CFGEdge(pred,handlerStart));
        }
      }
    }
  }
  return trapsThatAreHeads;
}

Fixed version (ground truth):
/** 
 * Method to compute the edges corresponding to exceptional control flow.
 * @param unitToDests A <tt>Map</tt> from {@link Unit}s to   {@link Collection}s of   {@link ExceptionalUnitGraph.ExceptionDest ExceptionDest}s which represent the handlers that might catch exceptions thrown by the <tt>Unit</tt>. This is an ``in parameter''.
 * @param unitToSuccs A <tt>Map</tt> from <tt>Unit</tt>s to {@link List}s of <tt>Unit</tt>s. This is an ``out parameter''; <tt>buildExceptionalEdges</tt> will add a mapping from every <tt>Unit</tt> in the body that may throw an exception that could be caught by a   {@link Trap} in the body to alist of its exceptional successors.
 * @param unitToPreds A <tt>Map</tt> from <tt>Unit</tt>s to <tt>List</tt>s of <tt>Unit</tt>s. This is an ``out parameter''; <tt>buildExceptionalEdges</tt> will add a mapping from each handler unit that may catch an exception to the list of <tt>Unit</tt>s whose exceptions it may catch.
 * @param omitExceptingUnitEdges Indicates whether to omitexceptional edges from excepting units which lack side effects
 * @return a {@link Set} of trap <tt>Unit</tt>s that might catch exceptions thrown by the first <tt>Unit</tt> in the  {@link Body}associated with the graph being constructed.  Such trap <tt>Unit</tt>s may need to be added to the list of heads (depending on your definition of heads), since they can be the first <tt>Unit</tt> in the <tt>Body</tt> which actually completes execution.
 */
protected Set buildExceptionalEdges(Map unitToDests,Map unitToSuccs,Map unitToPreds,boolean omitExceptingUnitEdges){
  Set trapsThatAreHeads=new ArraySet();
  Unit entryPoint=(Unit)unitChain.getFirst();
  for (Iterator it=unitToDests.entrySet().iterator(); it.hasNext(); ) {
    Map.Entry entry=(Map.Entry)it.next();
    Unit thrower=(Unit)entry.getKey();
    Collection dests=(Collection)entry.getValue();
    for (Iterator destIt=dests.iterator(); destIt.hasNext(); ) {
      ExceptionDest dest=(ExceptionDest)destIt.next();
      if (dest.trap() != null) {
        Unit catcher=dest.trap().getHandlerUnit();
        List throwersPreds=getUnexceptionalPredsOf(thrower);
        if (thrower == entryPoint) {
          trapsThatAreHeads.add(catcher);
        }
 else {
          for (Iterator j=throwersPreds.iterator(); j.hasNext(); ) {
            Unit pred=(Unit)j.next();
            addEdge(unitToSuccs,unitToPreds,pred,catcher);
          }
        }
        if ((!omitExceptingUnitEdges) || thrower instanceof ThrowInst || thrower instanceof ThrowStmt|| mightHaveSideEffects(thrower)) {
          addEdge(unitToSuccs,unitToPreds,thrower,catcher);
        }
      }
    }
  }
class CFGEdge {
    Unit head;
    Unit tail;
    CFGEdge(    Unit head,    Unit tail){
      if (tail == null)       throw new RuntimeException("String_Node_Str" + head.toString() + ','+ tail.toString()+ ')');
      this.head=head;
      this.tail=tail;
    }
    public boolean equals(    Object rhs){
      if (rhs == this) {
        return true;
      }
      if (!(rhs instanceof CFGEdge)) {
        return false;
      }
      CFGEdge rhsEdge=(CFGEdge)rhs;
      return ((this.head == rhsEdge.head) && (this.tail == rhsEdge.tail));
    }
    public int hashCode(){
      int result=17;
      result=37 * result + this.head.hashCode();
      result=37 * result + this.tail.hashCode();
      return result;
    }
  }
  LinkedList workList=new LinkedList();
  for (Iterator trapIt=body.getTraps().iterator(); trapIt.hasNext(); ) {
    Trap trap=(Trap)trapIt.next();
    Unit handlerStart=trap.getHandlerUnit();
    if (mightThrowToIntraproceduralCatcher(handlerStart)) {
      List handlerPreds=getUnexceptionalPredsOf(handlerStart);
      for (Iterator it=handlerPreds.iterator(); it.hasNext(); ) {
        Unit pred=(Unit)it.next();
        workList.addLast(new CFGEdge(pred,handlerStart));
      }
      handlerPreds=getExceptionalPredsOf(handlerStart);
      for (Iterator it=handlerPreds.iterator(); it.hasNext(); ) {
        Unit pred=(Unit)it.next();
        workList.addLast(new CFGEdge(pred,handlerStart));
      }
      if (trapsThatAreHeads.contains(handlerStart)) {
        workList.addLast(new CFGEdge(null,handlerStart));
      }
    }
  }
  while (workList.size() > 0) {
    CFGEdge edgeToThrower=(CFGEdge)workList.removeFirst();
    Unit pred=edgeToThrower.head;
    Unit thrower=edgeToThrower.tail;
    Collection throwerDests=getExceptionDests(thrower);
    for (Iterator i=throwerDests.iterator(); i.hasNext(); ) {
      ExceptionDest dest=(ExceptionDest)i.next();
      if (dest.trap() != null) {
        Unit handlerStart=dest.trap().getHandlerUnit();
        boolean edgeAdded=false;
        if (pred == null) {
          if (!trapsThatAreHeads.contains(handlerStart)) {
            trapsThatAreHeads.add(handlerStart);
            edgeAdded=true;
          }
        }
 else {
          if (!getExceptionalSuccsOf(pred).contains(handlerStart)) {
            addEdge(unitToSuccs,unitToPreds,pred,handlerStart);
            edgeAdded=true;
          }
        }
        if (edgeAdded && mightThrowToIntraproceduralCatcher(handlerStart)) {
          workList.addLast(new CFGEdge(pred,handlerStart));
        }
      }
    }
  }
  return trapsThatAreHeads;
}