Program: 74965
Project: 74965
Buggy source:
/** 
 * Get or put token(s) to the array of receivers, or both put and get at the same time. This method is commonly used by   {@link #getFromAll(Receiver[][],RendezvousDirector)},   {@link #getFromAny(Receiver[][],RendezvousDirector)},   {@link #putToAll(Token[][],Receiver[][],RendezvousDirector)},   {@link #putToAny(Token,Receiver[][],RendezvousDirector)}, and   {@link
     * #getFromAnyPutToAll(Receiver[][], Receiver[][], RendezvousDirector). The operation that it performs depends on the flag parameter. If a get is requested in the flag, getReceivers should contain the receivers to receive tokens; otherwise, getReceivers is ignored. If a put is requested in the flag, putReceivers should contain the receivers to put tokens to. The tokens are stored in the tokens parameter. If the put is to any of the receivers, the tokens parameter is the single token to put (of type}{  {@link Token}); if the put is to all of the receivers, the tokens parameter is a two-dimensional array of tokens (of type   {@link Token}[][]), one corresponding to a receiver in the two-dimensional array putReceivers. This method does not return until the requested operation is finished.
 * @param getReceivers The receivers from whith tokens are received.
 * @param putReceivers The receivers to which tokens are put to.
 * @param director The director.
 * @param tokens A token if the operation is to put to any of the receivers. A two-dimensional array of tokens if the operation is to put to all of the receivers. Ignored if the operation is to get tokens from the getReceivers only.
 * @param flag The flag representing the operation to be performed.
 * @return The map of results on the receivers that participate in therendezvous. Keys of the map are receivers; values of the map are the tokens on those receivers.
 * @exception IllegalActionException If the token is not acceptable to one of the ports (e.g., wrong type). This can happen only if the operation is put to all or put to any.
 * @exception TerminateProcessException If the actor to which this receiver belongs is to be terminated.
 */
private static Map _getOrPutTokens(Receiver[][] getReceivers,Receiver[][] putReceivers,RendezvousDirector director,Object tokens,int flag) throws IllegalActionException, TerminateProcessException {
  boolean isGet=(flag & GET) == GET;
  boolean isPut=(flag & PUT) == PUT;
  boolean isGetConditional=(flag & GET_CONDITIONAL) == GET_CONDITIONAL;
  boolean isPutConditional=(flag & PUT_CONDITIONAL) == PUT_CONDITIONAL;
  boolean isSymmetric=isPut && isGet;
  Map result=null;
synchronized (director) {
    Thread theThread=Thread.currentThread();
    Token token=tokens instanceof Token ? (Token)tokens : null;
    Token[][] tokenArray=tokens instanceof Token[][] ? (Token[][])tokens : null;
    if (isGet) {
      for (int i=0; i < getReceivers.length; i++) {
        if (getReceivers[i] != null) {
          for (int j=0; j < getReceivers[i].length; j++) {
            RendezvousReceiver receiver=(RendezvousReceiver)getReceivers[i][j];
            if (receiver != null) {
              receiver._getWaiting=theThread;
              receiver._getReceivers=getReceivers;
              receiver._getConditional=isGetConditional;
              if (isSymmetric) {
                receiver._channelIndex=i;
                receiver._symmetricPutReceivers=putReceivers;
              }
            }
          }
        }
      }
    }
    if (isPut) {
      for (int i=0; i < putReceivers.length; i++) {
        if (putReceivers[i] != null) {
          for (int j=0; j < putReceivers[i].length; j++) {
            RendezvousReceiver receiver=(RendezvousReceiver)putReceivers[i][j];
            if (receiver != null) {
              receiver._putWaiting=theThread;
              receiver._putReceivers=putReceivers;
              IOPort port=receiver.getContainer();
              if (isPutConditional) {
                receiver._putConditional=true;
                receiver._token=token == null ? null : port.convert(token);
              }
 else {
                receiver._putConditional=false;
                try {
                  token=tokenArray[i][j];
                }
 catch (                Throwable e) {
                }
                receiver._token=token == null ? null : port.convert(token);
              }
              if (isSymmetric) {
                receiver._symmetricGetReceivers=getReceivers;
              }
            }
          }
        }
      }
    }
    Set rendezvousReceivers;
    if (getReceivers != null) {
      rendezvousReceivers=_receiversReadyToCommit(getReceivers,false);
    }
 else {
      rendezvousReceivers=_receiversReadyToCommit(putReceivers,true);
    }
    if (rendezvousReceivers == null) {
      director.threadBlocked(theThread,null);
      while (result == null) {
        waitForChange(director);
        result=(Map)_getData(theThread);
      }
      _setData(theThread,null);
    }
 else {
      _commitRendezvous(rendezvousReceivers,director);
      result=(Map)_setData(theThread,null);
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Get or put token(s) to the array of receivers, or both put and get at the same time. This method is commonly used by   {@link #getFromAll(Receiver[][],RendezvousDirector)},   {@link #getFromAny(Receiver[][],RendezvousDirector)},   {@link #putToAll(Token[][],Receiver[][],RendezvousDirector)},   {@link #putToAny(Token,Receiver[][],RendezvousDirector)}, and   {@link
     * #getFromAnyPutToAll(Receiver[][], Receiver[][], RendezvousDirector). The operation that it performs depends on the flag parameter. If a get is requested in the flag, getReceivers should contain the receivers to receive tokens; otherwise, getReceivers is ignored. If a put is requested in the flag, putReceivers should contain the receivers to put tokens to. The tokens are stored in the tokens parameter. If the put is to any of the receivers, the tokens parameter is the single token to put (of type}{  {@link Token}); if the put is to all of the receivers, the tokens parameter is a two-dimensional array of tokens (of type   {@link Token}[][]), one corresponding to a receiver in the two-dimensional array putReceivers. This method does not return until the requested operation is finished.
 * @param getReceivers The receivers from whith tokens are received.
 * @param putReceivers The receivers to which tokens are put to.
 * @param director The director.
 * @param tokens A token if the operation is to put to any of the receivers. A two-dimensional array of tokens if the operation is to put to all of the receivers. Ignored if the operation is to get tokens from the getReceivers only.
 * @param flag The flag representing the operation to be performed.
 * @return The map of results on the receivers that participate in therendezvous. Keys of the map are receivers; values of the map are the tokens on those receivers.
 * @exception IllegalActionException If the token is not acceptable to one of the ports (e.g., wrong type). This can happen only if the operation is put to all or put to any.
 * @exception TerminateProcessException If the actor to which this receiver belongs is to be terminated.
 */
private static Map _getOrPutTokens(Receiver[][] getReceivers,Receiver[][] putReceivers,RendezvousDirector director,Object tokens,int flag) throws IllegalActionException, TerminateProcessException {
  boolean isGet=(flag & GET) == GET;
  boolean isPut=(flag & PUT) == PUT;
  boolean isGetConditional=(flag & GET_CONDITIONAL) == GET_CONDITIONAL;
  boolean isPutConditional=(flag & PUT_CONDITIONAL) == PUT_CONDITIONAL;
  boolean isSymmetric=isPut && isGet;
  Map result=null;
synchronized (director) {
    Thread theThread=Thread.currentThread();
    Token token=tokens instanceof Token ? (Token)tokens : null;
    Token[][] tokenArray=tokens instanceof Token[][] ? (Token[][])tokens : null;
    boolean cardinalityTest=true;
    if (!isGetConditional && !isPutConditional && getReceivers != null && putReceivers != null && getReceivers.length < putReceivers.length) {
      cardinalityTest=false;
    }
    if (cardinalityTest && isGet) {
      for (int i=0; i < getReceivers.length; i++) {
        if (getReceivers[i] != null) {
          for (int j=0; j < getReceivers[i].length; j++) {
            RendezvousReceiver receiver=(RendezvousReceiver)getReceivers[i][j];
            if (receiver != null) {
              receiver._getWaiting=theThread;
              receiver._getReceivers=getReceivers;
              receiver._getConditional=isGetConditional;
              if (isSymmetric) {
                receiver._channelIndex=i;
                receiver._symmetricPutReceivers=putReceivers;
              }
            }
          }
        }
      }
    }
    if (cardinalityTest && isPut) {
      for (int i=0; i < putReceivers.length; i++) {
        if (putReceivers[i] != null) {
          for (int j=0; j < putReceivers[i].length; j++) {
            RendezvousReceiver receiver=(RendezvousReceiver)putReceivers[i][j];
            if (receiver != null) {
              receiver._putWaiting=theThread;
              receiver._putReceivers=putReceivers;
              IOPort port=receiver.getContainer();
              if (isPutConditional) {
                receiver._putConditional=true;
                receiver._token=token == null ? null : port.convert(token);
              }
 else {
                receiver._putConditional=false;
                try {
                  token=tokenArray[i][j];
                }
 catch (                Throwable e) {
                }
                receiver._token=token == null ? null : port.convert(token);
              }
              if (isSymmetric) {
                receiver._symmetricGetReceivers=getReceivers;
              }
            }
          }
        }
      }
    }
    Set rendezvousReceivers=null;
    if (cardinalityTest && getReceivers != null) {
      rendezvousReceivers=_receiversReadyToCommit(getReceivers,false);
    }
 else     if (cardinalityTest) {
      rendezvousReceivers=_receiversReadyToCommit(putReceivers,true);
    }
    if (rendezvousReceivers == null) {
      director.threadBlocked(theThread,null);
      while (result == null) {
        waitForChange(director);
        result=(Map)_getData(theThread);
      }
      _setData(theThread,null);
    }
 else {
      _commitRendezvous(rendezvousReceivers,director);
      result=(Map)_setData(theThread,null);
    }
  }
  return result;
}