Program: 104404
Project: 104404
Buggy source:
/** 
 * Process a request from a distant contact
 * @param requestEvent the <tt>RequestEvent</tt> containing the newlyreceived request.
 */
public void processRequest(RequestEvent requestEvent){
  ServerTransaction serverTransaction=requestEvent.getServerTransaction();
  SipProvider jainSipProvider=(SipProvider)requestEvent.getSource();
  Request request=requestEvent.getRequest();
  if (serverTransaction == null) {
    try {
      serverTransaction=jainSipProvider.getNewServerTransaction(request);
    }
 catch (    TransactionAlreadyExistsException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return;
    }
catch (    TransactionUnavailableException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return;
    }
  }
  EventHeader eventHeader=(EventHeader)request.getHeader(EventHeader.NAME);
  if (eventHeader == null || !eventHeader.getEventType().equalsIgnoreCase("String_Node_Str")) {
    return;
  }
  if (request.getMethod().equals(Request.NOTIFY)) {
    Response response=null;
    logger.debug("String_Node_Str");
    SubscriptionStateHeader sstateHeader=(SubscriptionStateHeader)request.getHeader(SubscriptionStateHeader.NAME);
    if (sstateHeader == null) {
      logger.error("String_Node_Str");
      return;
    }
    CallIdHeader idheader=(CallIdHeader)request.getHeader(CallIdHeader.NAME);
    ContactSipImpl contact=(ContactSipImpl)this.subscribedContacts.get(idheader.getCallId());
    if (contact != null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED) && !contact.isResolved()) {
      logger.debug("String_Node_Str");
      return;
    }
    if (contact == null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      logger.debug("String_Node_Str" + idheader.getCallId());
synchronized (this.waitedCallIds) {
        this.waitedCallIds.remove(idheader.getCallId());
      }
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST,request);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      SipException e) {
        logger.error("String_Node_Str",e);
      }
catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str" + "String_Node_Str",e);
      }
      return;
    }
    ContentTypeHeader ctheader=(ContentTypeHeader)request.getHeader(ContentTypeHeader.NAME);
    if (ctheader != null && !ctheader.getContentSubType().equalsIgnoreCase(PIDF_XML)) {
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.UNSUPPORTED_MEDIA_TYPE,request);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      AcceptHeader acceptHeader=null;
      try {
        acceptHeader=this.parentProvider.getHeaderFactory().createAcceptHeader("String_Node_Str",PIDF_XML);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(acceptHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      SipException e) {
        logger.error("String_Node_Str",e);
      }
catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str" + "String_Node_Str",e);
      }
    }
    if (sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      if (contact != null) {
        terminateSubscription(contact);
        this.subscribedContacts.remove(serverTransaction.getDialog().getCallId().getCallId());
      }
synchronized (this.waitedCallIds) {
        this.waitedCallIds.remove(idheader.getCallId());
      }
    }
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
    }
 catch (    ParseException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    SipException e) {
      logger.error("String_Node_Str",e);
    }
catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str" + "String_Node_Str",e);
    }
    if (request.getRawContent() != null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      setPidfPresenceStatus(new String(request.getRawContent()));
    }
  }
 else   if (request.getMethod().equals(Request.SUBSCRIBE)) {
    FromHeader from=(FromHeader)request.getHeader(FromHeader.NAME);
    if (this.useDistantPA) {
      this.useDistantPA=false;
      if (this.republishTask != null) {
        this.republishTask.cancel();
      }
    }
    ContactSipImpl contact=(ContactSipImpl)resolveContactID(from.getAddress().getURI().toString());
    if (contact == null) {
      contact=new ContactSipImpl(from.getAddress().getURI().toString(),this.parentProvider);
      contact.setResolved(true);
      contact.setResolvable(false);
    }
    logger.debug(contact.toString() + "String_Node_Str" + "String_Node_Str");
    ExpiresHeader expHeader=request.getExpires();
    int expires;
    if (expHeader == null) {
      expires=SUBSCRIBE_DEFAULT_EXPIRE;
    }
 else {
      expires=expHeader.getExpires();
    }
    if (expires < SUBSCRIBE_MIN_EXPIRE && expires > 0 && expires < 3600) {
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.INTERVAL_TOO_BRIEF,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      MinExpiresHeader min=null;
      try {
        min=this.parentProvider.getHeaderFactory().createMinExpiresHeader(SUBSCRIBE_MIN_EXPIRE);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(min);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    if (this.ourWatchers.contains(contact)) {
      contact.getTimeoutTask().cancel();
      watcherTimeoutTask timeout=new watcherTimeoutTask(contact);
      contact.setTimeoutTask(timeout);
      this.timer.schedule(timeout,expires * 1000);
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str");
        return;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    Dialog dialog=contact.getServerDialog();
    if (expires == 0) {
      logger.debug("String_Node_Str" + contact + "String_Node_Str");
synchronized (this.ourWatchers) {
        this.ourWatchers.remove(contact);
      }
      contact.getTimeoutTask().cancel();
      contact.setServerDialog(null);
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(0);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContact()),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.TIMEOUT);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    contact.setServerDialog(serverTransaction.getDialog());
    dialog=contact.getServerDialog();
    Response response=null;
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
    }
 catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    response.setHeader(expHeader);
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    ClientTransaction transac=null;
    try {
      transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContact()),SubscriptionStateHeader.ACTIVE,null);
    }
 catch (    OperationFailedException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      dialog.sendRequest(transac);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
synchronized (this.ourWatchers) {
      this.ourWatchers.add(contact);
    }
    watcherTimeoutTask timeout=new watcherTimeoutTask(contact);
    contact.setTimeoutTask(timeout);
    this.timer.schedule(timeout,expires * 1000);
  }
 else   if (request.getMethod().equals(Request.PUBLISH)) {
    Response response=null;
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.NOT_IMPLEMENTED,request);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
  }
}

Fixed version (ground truth):
/** 
 * Process a request from a distant contact
 * @param requestEvent the <tt>RequestEvent</tt> containing the newlyreceived request.
 */
public void processRequest(RequestEvent requestEvent){
  ServerTransaction serverTransaction=requestEvent.getServerTransaction();
  SipProvider jainSipProvider=(SipProvider)requestEvent.getSource();
  Request request=requestEvent.getRequest();
  if (serverTransaction == null) {
    try {
      serverTransaction=jainSipProvider.getNewServerTransaction(request);
    }
 catch (    TransactionAlreadyExistsException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return;
    }
catch (    TransactionUnavailableException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return;
    }
  }
  EventHeader eventHeader=(EventHeader)request.getHeader(EventHeader.NAME);
  if (eventHeader == null || !eventHeader.getEventType().equalsIgnoreCase("String_Node_Str")) {
    return;
  }
  if (request.getMethod().equals(Request.NOTIFY)) {
    Response response=null;
    logger.debug("String_Node_Str");
    SubscriptionStateHeader sstateHeader=(SubscriptionStateHeader)request.getHeader(SubscriptionStateHeader.NAME);
    if (sstateHeader == null) {
      logger.error("String_Node_Str");
      return;
    }
    CallIdHeader idheader=(CallIdHeader)request.getHeader(CallIdHeader.NAME);
    ContactSipImpl contact=(ContactSipImpl)this.subscribedContacts.get(idheader.getCallId());
    if (contact != null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED) && !contact.isResolved()) {
      logger.debug("String_Node_Str");
    }
    if (contact == null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      logger.debug("String_Node_Str" + idheader.getCallId());
synchronized (this.waitedCallIds) {
        this.waitedCallIds.remove(idheader.getCallId());
      }
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST,request);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      SipException e) {
        logger.error("String_Node_Str",e);
      }
catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str" + "String_Node_Str",e);
      }
      return;
    }
    ContentTypeHeader ctheader=(ContentTypeHeader)request.getHeader(ContentTypeHeader.NAME);
    if (ctheader != null && !ctheader.getContentSubType().equalsIgnoreCase(PIDF_XML)) {
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.UNSUPPORTED_MEDIA_TYPE,request);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      AcceptHeader acceptHeader=null;
      try {
        acceptHeader=this.parentProvider.getHeaderFactory().createAcceptHeader("String_Node_Str",PIDF_XML);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(acceptHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      SipException e) {
        logger.error("String_Node_Str",e);
      }
catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str" + "String_Node_Str",e);
      }
    }
    if (sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      if (contact != null) {
        terminateSubscription(contact);
        this.subscribedContacts.remove(serverTransaction.getDialog().getCallId().getCallId());
        if (sstateHeader.getReasonCode().equals(SubscriptionStateHeader.DEACTIVATED)) {
          forcePollContact(contact);
        }
      }
synchronized (this.waitedCallIds) {
        this.waitedCallIds.remove(idheader.getCallId());
      }
    }
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
    }
 catch (    ParseException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    SipException e) {
      logger.error("String_Node_Str",e);
    }
catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str" + "String_Node_Str",e);
    }
    if (request.getRawContent() != null && !sstateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
      setPidfPresenceStatus(new String(request.getRawContent()));
    }
  }
 else   if (request.getMethod().equals(Request.SUBSCRIBE)) {
    FromHeader from=(FromHeader)request.getHeader(FromHeader.NAME);
    if (this.useDistantPA) {
      this.useDistantPA=false;
      if (this.republishTask != null) {
        this.republishTask.cancel();
      }
    }
    ContactSipImpl contact=(ContactSipImpl)resolveContactID(from.getAddress().getURI().toString());
    if (contact == null) {
      contact=new ContactSipImpl(from.getAddress().getURI().toString(),this.parentProvider);
      contact.setResolved(true);
      contact.setResolvable(false);
    }
    logger.debug(contact.toString() + "String_Node_Str" + "String_Node_Str");
    ExpiresHeader expHeader=request.getExpires();
    int expires;
    if (expHeader == null) {
      expires=SUBSCRIBE_DEFAULT_EXPIRE;
    }
 else {
      expires=expHeader.getExpires();
    }
    if (expires < SUBSCRIBE_MIN_EXPIRE && expires > 0 && expires < 3600) {
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.INTERVAL_TOO_BRIEF,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      MinExpiresHeader min=null;
      try {
        min=this.parentProvider.getHeaderFactory().createMinExpiresHeader(SUBSCRIBE_MIN_EXPIRE);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(min);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    if (this.ourWatchers.contains(contact)) {
      contact.getTimeoutTask().cancel();
      watcherTimeoutTask timeout=new watcherTimeoutTask(contact);
      contact.setTimeoutTask(timeout);
      this.timer.schedule(timeout,expires * 1000);
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str");
        return;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    Dialog dialog=contact.getServerDialog();
    if (expires == 0) {
      logger.debug("String_Node_Str" + contact + "String_Node_Str");
synchronized (this.ourWatchers) {
        this.ourWatchers.remove(contact);
      }
      contact.getTimeoutTask().cancel();
      contact.setServerDialog(null);
      Response response=null;
      try {
        response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(0);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContact()),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.TIMEOUT);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return;
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return;
      }
      return;
    }
    contact.setServerDialog(serverTransaction.getDialog());
    dialog=contact.getServerDialog();
    Response response=null;
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.OK,request);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
    }
 catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    response.setHeader(expHeader);
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    ClientTransaction transac=null;
    try {
      transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContact()),SubscriptionStateHeader.ACTIVE,null);
    }
 catch (    OperationFailedException e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      dialog.sendRequest(transac);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
synchronized (this.ourWatchers) {
      this.ourWatchers.add(contact);
    }
    watcherTimeoutTask timeout=new watcherTimeoutTask(contact);
    contact.setTimeoutTask(timeout);
    this.timer.schedule(timeout,expires * 1000);
  }
 else   if (request.getMethod().equals(Request.PUBLISH)) {
    Response response=null;
    try {
      response=this.parentProvider.getMessageFactory().createResponse(Response.NOT_IMPLEMENTED,request);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return;
    }
  }
}