Program: 104092
Project: 104092
Buggy source:
/** 
 * Process a request from a distant contact
 * @param requestEvent the <tt>RequestEvent</tt> containing the newlyreceived request.
 * @return <tt>true</tt> if the specified event has been handled by thisprocessor and shouldn't be offered to other processors registered for the same method; <tt>false</tt>, otherwise
 */
public boolean processRequest(RequestEvent requestEvent){
  if (this.presenceEnabled == false)   return false;
  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 false;
    }
catch (    TransactionUnavailableException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return false;
    }
  }
  EventHeader eventHeader=(EventHeader)request.getHeader(EventHeader.NAME);
  if (eventHeader == null || !eventHeader.getEventType().equalsIgnoreCase("String_Node_Str")) {
    return false;
  }
  boolean processed=false;
  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 false;
    }
    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 false;
      }
      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 true;
    }
    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 false;
      }
      AcceptHeader acceptHeader=null;
      try {
        acceptHeader=this.parentProvider.getHeaderFactory().createAcceptHeader("String_Node_Str",PIDF_XML);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      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 false;
    }
    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()));
    }
    processed=true;
  }
 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();
        this.republishTask=null;
      }
    }
    ContactSipImpl contact=(ContactSipImpl)resolveContactID(from.getAddress().getURI().toString());
    if (contact == null) {
      contact=new ContactSipImpl(from.getAddress(),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=PRESENCE_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 false;
      }
      MinExpiresHeader min=null;
      try {
        min=this.parentProvider.getHeaderFactory().createMinExpiresHeader(SUBSCRIBE_MIN_EXPIRE);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      response.setHeader(min);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    if (this.ourWatchers.contains(contact) && expires != 0 && contact.getServerDialog().equals(serverTransaction.getDialog())) {
      contact.getTimeoutTask().cancel();
      WatcherTimeoutTask timeout=new WatcherTimeoutTask(contact);
      contact.setTimeoutTask(timeout);
      getTimer().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 false;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str");
        return false;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    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 false;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(0);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.TIMEOUT);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    if (this.ourWatchers.contains(contact) && !contact.getServerDialog().equals(serverTransaction.getDialog())) {
      logger.debug("String_Node_Str" + contact + "String_Node_Str"+ "String_Node_Str");
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.REJECTED);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      contact.setServerDialog(null);
synchronized (this.ourWatchers) {
        this.ourWatchers.remove(contact);
      }
      if (contact.getTimeoutTask() != null) {
        contact.getTimeoutTask().cancel();
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
    }
synchronized (contact) {
      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 false;
    }
    try {
      expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
    }
 catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    response.setHeader(expHeader);
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    ClientTransaction transac=null;
    try {
      transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.ACTIVE,null);
    }
 catch (    OperationFailedException e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    try {
      dialog.sendRequest(transac);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
synchronized (this.ourWatchers) {
      this.ourWatchers.add(contact);
    }
    WatcherTimeoutTask timeout=new WatcherTimeoutTask(contact);
    contact.setTimeoutTask(timeout);
    getTimer().schedule(timeout,expires * 1000);
    processed=true;
  }
 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 false;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    processed=true;
  }
  return processed;
}

Fixed version (ground truth):
/** 
 * Process a request from a distant contact
 * @param requestEvent the <tt>RequestEvent</tt> containing the newlyreceived request.
 * @return <tt>true</tt> if the specified event has been handled by thisprocessor and shouldn't be offered to other processors registered for the same method; <tt>false</tt>, otherwise
 */
public boolean processRequest(RequestEvent requestEvent){
  if (this.presenceEnabled == false)   return false;
  ServerTransaction serverTransaction=requestEvent.getServerTransaction();
  SipProvider jainSipProvider=(SipProvider)requestEvent.getSource();
  Request request=requestEvent.getRequest();
  if (serverTransaction == null) {
    try {
      serverTransaction=SipStackSharing.getOrCreateServerTransaction(requestEvent);
    }
 catch (    TransactionAlreadyExistsException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return false;
    }
catch (    TransactionUnavailableException ex) {
      logger.error("String_Node_Str" + "String_Node_Str" + "String_Node_Str",ex);
      return false;
    }
  }
  EventHeader eventHeader=(EventHeader)request.getHeader(EventHeader.NAME);
  if (eventHeader == null || !eventHeader.getEventType().equalsIgnoreCase("String_Node_Str")) {
    return false;
  }
  boolean processed=false;
  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 false;
    }
    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 false;
      }
      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 true;
    }
    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 false;
      }
      AcceptHeader acceptHeader=null;
      try {
        acceptHeader=this.parentProvider.getHeaderFactory().createAcceptHeader("String_Node_Str",PIDF_XML);
      }
 catch (      ParseException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      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 false;
    }
    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()));
    }
    processed=true;
  }
 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();
        this.republishTask=null;
      }
    }
    ContactSipImpl contact=(ContactSipImpl)resolveContactID(from.getAddress().getURI().toString());
    if (contact == null) {
      contact=new ContactSipImpl(from.getAddress(),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=PRESENCE_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 false;
      }
      MinExpiresHeader min=null;
      try {
        min=this.parentProvider.getHeaderFactory().createMinExpiresHeader(SUBSCRIBE_MIN_EXPIRE);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      response.setHeader(min);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    if (this.ourWatchers.contains(contact) && expires != 0 && contact.getServerDialog().equals(serverTransaction.getDialog())) {
      contact.getTimeoutTask().cancel();
      WatcherTimeoutTask timeout=new WatcherTimeoutTask(contact);
      contact.setTimeoutTask(timeout);
      getTimer().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 false;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str");
        return false;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    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 false;
      }
      try {
        expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(0);
      }
 catch (      InvalidArgumentException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      response.setHeader(expHeader);
      try {
        serverTransaction.sendResponse(response);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.TIMEOUT);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      return true;
    }
    if (this.ourWatchers.contains(contact) && !contact.getServerDialog().equals(serverTransaction.getDialog())) {
      logger.debug("String_Node_Str" + contact + "String_Node_Str"+ "String_Node_Str");
      ClientTransaction transac=null;
      try {
        transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.TERMINATED,SubscriptionStateHeader.REJECTED);
      }
 catch (      OperationFailedException e) {
        logger.error("String_Node_Str",e);
        return false;
      }
      contact.setServerDialog(null);
synchronized (this.ourWatchers) {
        this.ourWatchers.remove(contact);
      }
      if (contact.getTimeoutTask() != null) {
        contact.getTimeoutTask().cancel();
      }
      try {
        dialog.sendRequest(transac);
      }
 catch (      Exception e) {
        logger.error("String_Node_Str",e);
        return false;
      }
    }
synchronized (contact) {
      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 false;
    }
    try {
      expHeader=this.parentProvider.getHeaderFactory().createExpiresHeader(expires);
    }
 catch (    InvalidArgumentException e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    response.setHeader(expHeader);
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    ClientTransaction transac=null;
    try {
      transac=createNotify(contact,getPidfPresenceStatus((ContactSipImpl)getLocalContactForDst(contact)),SubscriptionStateHeader.ACTIVE,null);
    }
 catch (    OperationFailedException e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    try {
      dialog.sendRequest(transac);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
synchronized (this.ourWatchers) {
      this.ourWatchers.add(contact);
    }
    WatcherTimeoutTask timeout=new WatcherTimeoutTask(contact);
    contact.setTimeoutTask(timeout);
    getTimer().schedule(timeout,expires * 1000);
    processed=true;
  }
 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 false;
    }
    try {
      serverTransaction.sendResponse(response);
    }
 catch (    Exception e) {
      logger.error("String_Node_Str",e);
      return false;
    }
    processed=true;
  }
  return processed;
}