Program: 104257
Project: 104257
Buggy source:
/** 
 * Creates an SDP description of this session using the offer descirption (if not null) for limiting. The intendedDestination parameter, which may contain the address that the offer is to be sent to, will only be used if the <tt>offer</tt> or its connection parameter are <tt>null</tt>. In the oposite case we are using the address provided in the connection param as an intended destination.
 * @param offer the call participant meant to receive the offer or null ifwe are to construct our own offer.
 * @param intendedDestination the address of the call participant that thedescriptions is to be sent to.
 * @return a SessionDescription of this CallSession.
 * @throws MediaException code INTERNAL_ERROR if we get an SDP exceptionwhile creating and/or parsing the sdp description.
 */
private SessionDescription createSessionDescription(SessionDescription offer,InetAddress intendedDestination) throws MediaException {
  SdpFactory sdpFactory=mediaServCallback.getSdpFactory();
  try {
    SessionDescription sessDescr=sdpFactory.createSessionDescription();
    Version v=sdpFactory.createVersion(0);
    sessDescr.setVersion(v);
    NetworkAddressManagerService netAddressManager=MediaActivator.getNetworkAddressManagerService();
    if (offer != null) {
      Connection c=offer.getConnection();
      if (c != null) {
        try {
          intendedDestination=NetworkUtils.getInetAddress(c.getAddress());
        }
 catch (        SdpParseException ex) {
          logger.warn("String_Node_Str" + c.toString() + "String_Node_Str",ex);
        }
catch (        UnknownHostException ex) {
          logger.warn("String_Node_Str" + c.toString() + "String_Node_Str",ex);
        }
      }
      Iterator<MediaDescription> mediaDescriptions=offer.getMediaDescriptions(true).iterator();
      while (mediaDescriptions.hasNext()) {
        Connection conn=mediaDescriptions.next().getConnection();
        if (conn != null) {
          try {
            intendedDestination=NetworkUtils.getInetAddress(conn.getAddress());
            break;
          }
 catch (          UnknownHostException e) {
            logger.debug("String_Node_Str" + "String_Node_Str" + conn.getAddress(),e);
          }
        }
      }
    }
    boolean allocateMediaPorts=false;
    boolean startStreaming=false;
    if ((audioSessionAddress == null) || (videoSessionAddress == null)) {
      allocateMediaPorts=true;
    }
 else {
      if (((lastIntendedDestination == null) && (intendedDestination != null)) || ((lastIntendedDestination != null) && !lastIntendedDestination.equals(intendedDestination))) {
        startStreaming=stopStreaming();
        audioRtpManager=RTPManager.newInstance();
        videoRtpManager=RTPManager.newInstance();
        allocateMediaPorts=true;
      }
    }
    if (allocateMediaPorts) {
      allocateMediaPorts(intendedDestination);
      lastIntendedDestination=intendedDestination;
      if (startStreaming) {
        startStreaming();
        applyOnHold();
      }
    }
    InetAddress publicIpAddress=audioPublicAddress.getAddress();
    String addrType=publicIpAddress instanceof Inet6Address ? Connection.IP6 : Connection.IP4;
    Origin o=sdpFactory.createOrigin(call.getProtocolProvider().getAccountID().getUserID(),0,0,"String_Node_Str",addrType,publicIpAddress.getHostAddress());
    sessDescr.setOrigin(o);
    Connection c=sdpFactory.createConnection("String_Node_Str",addrType,publicIpAddress.getHostAddress());
    sessDescr.setConnection(c);
    sessDescr.setSessionName(sdpFactory.createSessionName("String_Node_Str"));
    TimeDescription t=sdpFactory.createTimeDescription();
    Vector<TimeDescription> timeDescs=new Vector<TimeDescription>();
    timeDescs.add(t);
    sessDescr.setTimeDescriptions(timeDescs);
    Vector offeredMediaDescriptions=null;
    if (offer != null)     offeredMediaDescriptions=offer.getMediaDescriptions(false);
    logger.debug("String_Node_Str" + audioPublicAddress + "String_Node_Str"+ videoPublicAddress);
    Vector mediaDescs=createMediaDescriptions(offeredMediaDescriptions,audioPublicAddress,videoPublicAddress);
    sessDescr.setMediaDescriptions(mediaDescs);
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + sessDescr.toString());
    }
    return sessDescr;
  }
 catch (  SdpException exc) {
    throw new MediaException("String_Node_Str" + "String_Node_Str",MediaException.INTERNAL_ERROR,exc);
  }
}

Fixed version (ground truth):
/** 
 * Creates an SDP description of this session using the offer descirption (if not null) for limiting. The intendedDestination parameter, which may contain the address that the offer is to be sent to, will only be used if the <tt>offer</tt> or its connection parameter are <tt>null</tt>. In the oposite case we are using the address provided in the connection param as an intended destination.
 * @param offer the call participant meant to receive the offer or null ifwe are to construct our own offer.
 * @param intendedDestination the address of the call participant that thedescriptions is to be sent to.
 * @return a SessionDescription of this CallSession.
 * @throws MediaException code INTERNAL_ERROR if we get an SDP exceptionwhile creating and/or parsing the sdp description.
 */
private SessionDescription createSessionDescription(SessionDescription offer,InetAddress intendedDestination) throws MediaException {
  SdpFactory sdpFactory=mediaServCallback.getSdpFactory();
  try {
    SessionDescription sessDescr=sdpFactory.createSessionDescription();
    Version v=sdpFactory.createVersion(0);
    sessDescr.setVersion(v);
    NetworkAddressManagerService netAddressManager=MediaActivator.getNetworkAddressManagerService();
    if (offer != null) {
      Connection c=offer.getConnection();
      if (c != null) {
        try {
          intendedDestination=NetworkUtils.getInetAddress(c.getAddress());
        }
 catch (        SdpParseException ex) {
          logger.warn("String_Node_Str" + c.toString() + "String_Node_Str",ex);
        }
catch (        UnknownHostException ex) {
          logger.warn("String_Node_Str" + c.toString() + "String_Node_Str",ex);
        }
      }
      Iterator<MediaDescription> mediaDescriptions=offer.getMediaDescriptions(true).iterator();
      while (mediaDescriptions.hasNext()) {
        Connection conn=mediaDescriptions.next().getConnection();
        if (conn != null) {
          try {
            intendedDestination=NetworkUtils.getInetAddress(conn.getAddress());
            break;
          }
 catch (          UnknownHostException e) {
            logger.debug("String_Node_Str" + "String_Node_Str" + conn.getAddress(),e);
          }
        }
      }
    }
    boolean allocateMediaPorts=false;
    boolean startStreaming=false;
    if ((audioSessionAddress == null) || (videoSessionAddress == null)) {
      allocateMediaPorts=true;
    }
 else {
      if (((lastIntendedDestination == null) && (intendedDestination != null)) || ((lastIntendedDestination != null) && !lastIntendedDestination.equals(intendedDestination))) {
        startStreaming=stopStreaming();
        audioRtpManager=RTPManager.newInstance();
        videoRtpManager=RTPManager.newInstance();
        allocateMediaPorts=true;
      }
    }
    if (allocateMediaPorts) {
      allocateMediaPorts(intendedDestination);
      lastIntendedDestination=intendedDestination;
      if (startStreaming) {
        startStreaming();
        applyOnHold();
      }
    }
    InetAddress publicIpAddress=audioPublicAddress.getAddress();
    String addrType=publicIpAddress instanceof Inet6Address ? Connection.IP6 : Connection.IP4;
    Origin o=sdpFactory.createOrigin(call.getProtocolProvider().getAccountID().getUserID(),0,0,"String_Node_Str",addrType,publicIpAddress.getHostAddress());
    sessDescr.setOrigin(o);
    Connection c=sdpFactory.createConnection("String_Node_Str",addrType,publicIpAddress.getHostAddress());
    sessDescr.setConnection(c);
    sessDescr.setSessionName(sdpFactory.createSessionName("String_Node_Str"));
    TimeDescription t=sdpFactory.createTimeDescription();
    Vector<TimeDescription> timeDescs=new Vector<TimeDescription>();
    timeDescs.add(t);
    sessDescr.setTimeDescriptions(timeDescs);
    Vector<MediaDescription> offeredMediaDescriptions=null;
    if (offer != null)     offeredMediaDescriptions=offer.getMediaDescriptions(false);
    logger.debug("String_Node_Str" + audioPublicAddress + "String_Node_Str"+ videoPublicAddress);
    Vector<MediaDescription> mediaDescs=createMediaDescriptions(offeredMediaDescriptions,audioPublicAddress,videoPublicAddress);
    sessDescr.setMediaDescriptions(mediaDescs);
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + sessDescr.toString());
    }
    return sessDescr;
  }
 catch (  SdpException exc) {
    throw new MediaException("String_Node_Str" + "String_Node_Str",MediaException.INTERNAL_ERROR,exc);
  }
}