Program: 76534
Project: 76534
Buggy source:
/** 
 * The heart of the director that responds when a deadlock is  detected. It is where nearly all the control for the  simulation at this level in the hierarchy is located. <p> Deadlock occurs if the number of blocked and delayed process  equals the number of active processes. The method looks for  three cases in the following order: are there topology changes  waiting to happen, are there any process delayed, are all the  processses blocked trying to rendezvous.  <p> If there are changes to the topology waiting to happen, they are  performed and the simulation continues. Note that the result of  performing the topology changes may be to remove the deadlock  that had occured. <p> If the number of delayed processes is greater than zero, then  <i> time deadlock</i> has occured. Time is advanced and at least  one of the delayed actors will wake up and continue. Note that  time can be advanced to the current time. This happens if one of the  delayed actors delayed with a delta delay of zero. Otherwise the  simulation time is increased as well as being advanced. Current time is defined as the double value returned by  getCurrentTime plus/minus 10e-10. <p> If all the processes are blocked, then <i>real deadlock</i> has  occured. This method returns true, indicating the end of one  iteration one level up in the hierarchy. If there is no level  above this one, then real deadlock marks the end of the simulation.
 * @return True if real deadlock occured, false otherwise.
 */
protected synchronized boolean _handleDeadlock(){
  try {
    if (_actorsActive == (_actorsBlocked + _actorsDelayed)) {
      if (_topologyChangesPending) {
        System.out.println("String_Node_Str");
        _processTopologyRequests();
        LinkedList newThreads=new LinkedList();
        Enumeration newActors=_newActors();
        while (newActors.hasMoreElements()) {
          Actor actor=(Actor)newActors.nextElement();
          System.out.println("String_Node_Str" + ((Nameable)actor).getName() + "String_Node_Str");
          increaseActiveCount();
          actor.createReceivers();
          actor.initialize();
          String name=((Nameable)actor).getName();
          ProcessThread pnt=new ProcessThread(actor,this,name);
          newThreads.insertFirst(pnt);
        }
        Enumeration allThreads=newThreads.elements();
        while (allThreads.hasMoreElements()) {
          ProcessThread p=(ProcessThread)allThreads.nextElement();
          p.start();
          _threadList.insertFirst(p);
        }
        _topologyChangesPending=false;
        _checkForDeadlock();
        System.out.println("String_Node_Str" + "String_Node_Str");
      }
 else       if (_actorsDelayed > 0) {
        System.out.println("String_Node_Str");
        double nextTime=_getNextTime();
        System.out.println("String_Node_Str" + "String_Node_Str" + nextTime);
        _currentTime=nextTime;
        boolean done=false;
        while (!done && _delayedActorList.size() > 0) {
          DelayListLink val=(DelayListLink)_delayedActorList.first();
          double tolerance=Math.pow(10,-10);
          if (Math.abs(val._resumeTime - nextTime) < tolerance) {
            _delayedActorList.removeFirst();
            val._actor._continue();
            System.out.println("String_Node_Str" + "String_Node_Str" + val._resumeTime);
            _actorsDelayed--;
          }
 else {
            done=true;
          }
        }
      }
 else {
        System.out.println("String_Node_Str");
        return true;
      }
    }
    System.out.println("String_Node_Str");
    this.wait();
    return false;
  }
 catch (  InterruptedException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
catch (  TopologyChangeFailedException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str");
  }
catch (  IllegalActionException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * The heart of the director that responds when a deadlock is  detected. It is where nearly all the control for the  simulation at this level in the hierarchy is located. <p> Deadlock occurs if the number of blocked and delayed process  equals the number of active processes. The method looks for  three cases in the following order: are there topology changes  waiting to happen, are there any process delayed, are all the  processses blocked trying to rendezvous.  <p> If there are changes to the topology waiting to happen, they are  performed and the simulation continues. Note that the result of  performing the topology changes may be to remove the deadlock  that had occured. <p> If the number of delayed processes is greater than zero, then  <i> time deadlock</i> has occured. Time is advanced and at least  one of the delayed actors will wake up and continue. Note that  time can be advanced to the current time. This happens if one of the  delayed actors delayed with a delta delay of zero. Otherwise the  simulation time is increased as well as being advanced. Current time is defined as the double value returned by  getCurrentTime plus/minus 10e-10. <p> If all the processes are blocked, then <i>real deadlock</i> has  occured. This method returns true, indicating the end of one  iteration one level up in the hierarchy. If there is no level  above this one, then real deadlock marks the end of the simulation.
 * @return True if real deadlock occured, false otherwise.
 */
protected synchronized boolean _handleDeadlock(){
  try {
    if (_actorsActive == (_actorsBlocked + _actorsDelayed)) {
      if (_topologyChangesPending) {
        System.out.println("String_Node_Str");
        _processTopologyRequests();
        LinkedList newThreads=new LinkedList();
        Enumeration newActors=_newActors();
        while (newActors.hasMoreElements()) {
          Actor actor=(Actor)newActors.nextElement();
          System.out.println("String_Node_Str" + ((Nameable)actor).getName() + "String_Node_Str");
          increaseActiveCount();
          actor.createReceivers();
          actor.initialize();
          String name=((Nameable)actor).getName();
          ProcessThread pnt=new ProcessThread(actor,this,name);
          newThreads.insertFirst(pnt);
        }
        Enumeration allThreads=newThreads.elements();
        while (allThreads.hasMoreElements()) {
          ProcessThread p=(ProcessThread)allThreads.nextElement();
          p.start();
          _threadList.insertFirst(p);
        }
        _topologyChangesPending=false;
        return false;
      }
 else       if (_actorsDelayed > 0) {
        System.out.println("String_Node_Str");
        double nextTime=_getNextTime();
        System.out.println("String_Node_Str" + "String_Node_Str" + nextTime);
        _currentTime=nextTime;
        boolean done=false;
        while (!done && _delayedActorList.size() > 0) {
          DelayListLink val=(DelayListLink)_delayedActorList.first();
          double tolerance=Math.pow(10,-10);
          if (Math.abs(val._resumeTime - nextTime) < tolerance) {
            _delayedActorList.removeFirst();
            val._actor._continue();
            System.out.println("String_Node_Str" + "String_Node_Str" + val._resumeTime);
            _actorsDelayed--;
          }
 else {
            done=true;
          }
        }
      }
 else {
        System.out.println("String_Node_Str");
        return true;
      }
    }
    System.out.println("String_Node_Str");
    this.wait();
    return false;
  }
 catch (  InterruptedException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
catch (  TopologyChangeFailedException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str");
  }
catch (  IllegalActionException ex) {
    throw new InvalidStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  }
}