Program: 98417
Project: 98417
Buggy source:
public final void sendSipTermination(final JingleIQ iq,final CallSession callSession){
  try {
    JID from;
    Message lastResponse=callSession.getLastSentResponse();
    if (lastResponse != null && lastResponse.getContactHeader() != null) {
      from=Participants.getFromJidForResponse(lastResponse);
      if (sipToJingleBind != null) {
        from=sipToJingleBind.getXmppTo(from,callSession.getLastReceivedJingle());
      }
      if (!from.toBareJID().equals(iq.getFrom().toBareJID())) {
        lastResponse=null;
      }
      if (sipToJingleBind != null) {
        iq.setFrom(sipToJingleBind.getSipFrom(iq.getFrom()));
      }
    }
    if (lastResponse != null && (lastResponse.isRinging() || lastResponse.isTrying())) {
      if (iq.getJingle().getReason() != null && iq.getJingle().getReason().getType().equals(Reason.Type.media_error)) {
        lastResponse.setStatusLine(new StatusLine(415,"String_Node_Str"));
      }
 else {
        lastResponse.setStatusLine(new StatusLine(480,"String_Node_Str"));
      }
      gatewayRouter.routeSIP(lastResponse,callSession.getUser());
    }
 else {
      lastResponse=callSession.getLastReceivedResponse();
      final Message lastSentRequest=callSession.getLastSentRequest();
      if (lastResponse == null || (lastResponse.isRinging() || lastResponse.isTrying())) {
        Message message=callSession.getLastSentRequest();
        if (message == null) {
          message=callSession.getLastReceivedRequest();
        }
        if (message == null) {
          message=callSession.getLastMessage();
        }
        final Message cancel=SipProcessor.createSipCancel(message);
        cancel.setSendTo(lastSentRequest.getSendTo());
        cancel.setArrivedAt(lastSentRequest.getArrivedAt());
        callSession.addSentRequest(cancel);
        callSession.setRetries(2);
        gatewayRouter.routeSIP(cancel,callSession.getUser());
      }
 else {
        final Message bye=SipProcessor.createSipBye(iq,sipProviderInfo,lastResponse,callSession);
        Message msg=lastSentRequest;
        if (msg == null) {
          msg=callSession.getLastReceivedRequest();
          if (msg == null) {
            log.debug("String_Node_Str");
          }
        }
        if (msg == null) {
          log.warn("String_Node_Str");
          return;
        }
        bye.setSendTo(msg.getSendTo());
        bye.setArrivedAt(msg.getArrivedAt());
        gatewayRouter.routeSIP(bye,callSession.getUser());
        final ContactHeader contact=msg.getContactHeader();
        if (contact != null) {
          final SipURL url=contact.getNameAddress().getAddress();
          if (url.getHost() != null && url.getPort() > 0 && url.getPort() < 70000) {
            gatewayRouter.routeSIP(bye,callSession.getUser());
            gatewayRouter.routeSIP(bye,callSession.getUser());
          }
        }
      }
    }
  }
 catch (  JingleSipException e) {
    log.warn("String_Node_Str",e);
  }
catch (  SipParsingException e) {
    log.warn("String_Node_Str",e);
  }
}

Fixed version (ground truth):
public final void sendSipTermination(final JingleIQ iq,final CallSession callSession){
  try {
    JID from;
    Message lastResponse=callSession.getLastSentResponse();
    if (lastResponse != null && lastResponse.getContactHeader() != null) {
      from=Participants.getFromJidForResponse(lastResponse);
      if (sipToJingleBind != null) {
        from=sipToJingleBind.getXmppTo(from,callSession.getLastReceivedJingle());
      }
      if (!from.toBareJID().equals(iq.getFrom().toBareJID())) {
        lastResponse=null;
      }
      if (sipToJingleBind != null && sipToJingleBind.getSipFrom(iq.getFrom()) != null) {
        iq.setFrom(sipToJingleBind.getSipFrom(iq.getFrom()));
      }
    }
    if (lastResponse != null && (lastResponse.isRinging() || lastResponse.isTrying())) {
      if (iq.getJingle().getReason() != null && iq.getJingle().getReason().getType().equals(Reason.Type.media_error)) {
        lastResponse.setStatusLine(new StatusLine(415,"String_Node_Str"));
      }
 else {
        lastResponse.setStatusLine(new StatusLine(480,"String_Node_Str"));
      }
      gatewayRouter.routeSIP(lastResponse,callSession.getUser());
    }
 else {
      lastResponse=callSession.getLastReceivedResponse();
      if (lastResponse == null) {
        lastResponse=callSession.getLastSentResponse();
      }
      final Message lastSentRequest=callSession.getLastSentRequest();
      if (lastResponse == null || (lastResponse.isRinging() || lastResponse.isTrying())) {
        Message message=callSession.getLastSentRequest();
        if (message == null) {
          message=callSession.getLastReceivedRequest();
        }
        if (message == null) {
          message=callSession.getLastMessage();
        }
        final Message cancel=SipProcessor.createSipCancel(message);
        cancel.setSendTo(message.getSendTo());
        cancel.setArrivedAt(message.getArrivedAt());
        callSession.addSentRequest(cancel);
        callSession.setRetries(2);
        gatewayRouter.routeSIP(cancel,callSession.getUser());
      }
 else {
        final Message bye=SipProcessor.createSipBye(iq,sipProviderInfo,lastResponse,callSession);
        Message msg=lastSentRequest;
        if (msg == null) {
          msg=callSession.getLastReceivedRequest();
          if (msg == null) {
            log.debug("String_Node_Str");
          }
        }
        if (msg == null) {
          log.warn("String_Node_Str");
          return;
        }
        bye.setSendTo(msg.getSendTo());
        bye.setArrivedAt(msg.getArrivedAt());
        gatewayRouter.routeSIP(bye,callSession.getUser());
        final ContactHeader contact=msg.getContactHeader();
        if (contact != null) {
          final SipURL url=contact.getNameAddress().getAddress();
          if (url.getHost() != null && url.getPort() > 0 && url.getPort() < 70000) {
            gatewayRouter.routeSIP(bye,callSession.getUser());
            gatewayRouter.routeSIP(bye,callSession.getUser());
          }
        }
      }
    }
  }
 catch (  JingleSipException e) {
    log.warn("String_Node_Str",e);
  }
catch (  SipParsingException e) {
    log.warn("String_Node_Str",e);
  }
}