Program: 104400
Project: 104400
Buggy source:
/** 
 * Requests the provider to enter into a status corresponding to the specified paramters.
 * @param status the PresenceStatus as returned bygetRequestableStatusSet
 * @param statusMessage the message that should be set as the reason toenter that status
 * @throws IllegalArgumentException if the status requested is not avalid PresenceStatus supported by this provider.
 * @throws IllegalStateException if the provider is not currentlyregistered.
 * @throws OperationFailedException with code NETWORK_FAILURE ifpublishing the status fails due to a network error.
 */
public void publishPresenceStatus(PresenceStatus status,String statusMsg) throws IllegalArgumentException, IllegalStateException, OperationFailedException {
  PresenceStatus oldStatus=this.presenceStatus;
  this.presenceStatus=status;
  String oldMessage=this.statusMessage;
  this.statusMessage=statusMsg;
  this.fireProviderStatusChangeEvent(oldStatus);
  this.fireProviderMsgStatusChangeEvent(oldMessage);
  if (!status.equals(SipStatusEnum.OFFLINE)) {
    assertConnected();
  }
  if (status.equals(SipStatusEnum.OFFLINE)) {
    unsubscribeToAllContact();
  }
  if (this.useDistantPA) {
    Request req=createPublish(PUBLISH_DEFAULT_EXPIRE,true);
    if (status.equals(SipStatusEnum.OFFLINE)) {
synchronized (this.waitedCallIds) {
        this.waitedCallIds.add(((CallIdHeader)req.getHeader(CallIdHeader.NAME)).getCallId());
      }
    }
    ClientTransaction transac=null;
    try {
      transac=this.parentProvider.getDefaultJainSipProvider().getNewClientTransaction(req);
    }
 catch (    TransactionUnavailableException e) {
      logger.debug("String_Node_Str",e);
      throw new OperationFailedException("String_Node_Str",OperationFailedException.NETWORK_FAILURE);
    }
    try {
      transac.sendRequest();
    }
 catch (    SipException e) {
      logger.debug("String_Node_Str");
      throw new OperationFailedException("String_Node_Str",OperationFailedException.NETWORK_FAILURE);
    }
  }
 else {
synchronized (this.ourWatchers) {
      Iterator iter=this.ourWatchers.iterator();
      ContactSipImpl me=(ContactSipImpl)getLocalContact();
      while (iter.hasNext()) {
        ContactSipImpl contact=(ContactSipImpl)iter.next();
        if (!contact.isResolved()) {
          continue;
        }
        ClientTransaction transac=null;
        try {
          if (status.equals(SipStatusEnum.OFFLINE)) {
            transac=createNotify(contact,getPidfPresenceStatus(me),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.PROBATION);
synchronized (this.waitedCallIds) {
              this.waitedCallIds.add(transac.getDialog().getCallId().getCallId());
            }
          }
 else {
            transac=createNotify(contact,getPidfPresenceStatus(me),SubscriptionStateHeader.ACTIVE,null);
          }
        }
 catch (        OperationFailedException e) {
          logger.debug("String_Node_Str",e);
          return;
        }
        try {
          contact.getServerDialog().sendRequest(transac);
        }
 catch (        Exception e) {
          logger.debug("String_Node_Str");
          return;
        }
      }
      if (status.equals(SipStatusEnum.OFFLINE)) {
synchronized (this.ourWatchers) {
          this.ourWatchers.removeAllElements();
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Requests the provider to enter into a status corresponding to the specified paramters.
 * @param status the PresenceStatus as returned bygetRequestableStatusSet
 * @param statusMessage the message that should be set as the reason toenter that status
 * @throws IllegalArgumentException if the status requested is not avalid PresenceStatus supported by this provider.
 * @throws IllegalStateException if the provider is not currentlyregistered.
 * @throws OperationFailedException with code NETWORK_FAILURE ifpublishing the status fails due to a network error.
 */
public void publishPresenceStatus(PresenceStatus status,String statusMsg) throws IllegalArgumentException, IllegalStateException, OperationFailedException {
  PresenceStatus oldStatus=this.presenceStatus;
  this.presenceStatus=status;
  String oldMessage=this.statusMessage;
  this.statusMessage=statusMsg;
  this.fireProviderStatusChangeEvent(oldStatus);
  this.fireProviderMsgStatusChangeEvent(oldMessage);
  if (!status.equals(SipStatusEnum.OFFLINE)) {
    assertConnected();
  }
  if (status.equals(SipStatusEnum.OFFLINE)) {
    unsubscribeToAllContact();
  }
  if (this.useDistantPA) {
    Request req=createPublish(PUBLISH_DEFAULT_EXPIRE,true);
    if (status.equals(SipStatusEnum.OFFLINE)) {
synchronized (this.waitedCallIds) {
        this.waitedCallIds.add(((CallIdHeader)req.getHeader(CallIdHeader.NAME)).getCallId());
      }
    }
    ClientTransaction transac=null;
    try {
      transac=this.parentProvider.getDefaultJainSipProvider().getNewClientTransaction(req);
    }
 catch (    TransactionUnavailableException e) {
      logger.error("String_Node_Str",e);
      throw new OperationFailedException("String_Node_Str",OperationFailedException.NETWORK_FAILURE);
    }
    try {
      transac.sendRequest();
    }
 catch (    SipException e) {
      logger.error("String_Node_Str");
      throw new OperationFailedException("String_Node_Str",OperationFailedException.NETWORK_FAILURE);
    }
  }
 else {
synchronized (this.ourWatchers) {
      Iterator iter=this.ourWatchers.iterator();
      ContactSipImpl me=(ContactSipImpl)getLocalContact();
      while (iter.hasNext()) {
        ContactSipImpl contact=(ContactSipImpl)iter.next();
        if (!contact.isResolved()) {
          continue;
        }
        ClientTransaction transac=null;
        try {
          if (status.equals(SipStatusEnum.OFFLINE)) {
            transac=createNotify(contact,getPidfPresenceStatus(me),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.PROBATION);
synchronized (this.waitedCallIds) {
              this.waitedCallIds.add(transac.getDialog().getCallId().getCallId());
            }
          }
 else {
            transac=createNotify(contact,getPidfPresenceStatus(me),SubscriptionStateHeader.ACTIVE,null);
          }
        }
 catch (        OperationFailedException e) {
          logger.error("String_Node_Str",e);
          return;
        }
        try {
          contact.getServerDialog().sendRequest(transac);
        }
 catch (        Exception e) {
          logger.error("String_Node_Str",e);
          return;
        }
      }
      if (status.equals(SipStatusEnum.OFFLINE)) {
synchronized (this.ourWatchers) {
          this.ourWatchers.removeAllElements();
        }
      }
    }
  }
}