Program: 103676
Project: 103676
Buggy source:
/** 
 * Creates a new <tt>MediaDescription</tt> instance according to the specified <tt>formats</tt>, <tt>connector</tt> and <tt>direction</tt>, and using the <tt>dynamicPayloadTypes</tt> registry to handle dynamic payload type registrations. The type (e.g. audio/video) of the media description is determined via from the type of the first <tt>MediaFormat</tt> in the <tt>formats</tt> list.
 * @param formats the list of formats that should be advertised in the newlycreated <tt>MediaDescription</tt>.
 * @param connector the socket couple that will be used for the media streamwhich we are advertising with the media description created here.
 * @param direction the direction of the media stream that we are describinghere.
 * @param rtpExtensions a list of <tt>RTPExtension</tt>s supported by the<tt>MediaDevice</tt> that we will be advertising.
 * @param dynamicPayloadTypes a reference to the<tt>DynamicPayloadTypeRegistry</tt> that we should be using to lookup and register dynamic RTP mappings.
 * @param rtpExtensionsRegistry a reference to the<tt>DynamicRTPExtensionRegistry</tt> that we should be using to lookup and register URN to ID mappings.
 * @return the newly create SDP <tt>MediaDescription</tt>.
 * @throws OperationFailedException in case we fail to get payload typenumbers for dynamic payload types or in case our SDP generation fails for some other reason.
 */
public static MediaDescription createMediaDescription(List<MediaFormat> formats,StreamConnector connector,MediaDirection direction,List<RTPExtension> rtpExtensions,DynamicPayloadTypeRegistry dynamicPayloadTypes,DynamicRTPExtensionsRegistry rtpExtensionsRegistry) throws OperationFailedException {
  int[] payloadTypesArray=new int[formats.size()];
  Vector<Attribute> mediaAttributes=new Vector<Attribute>(2 * payloadTypesArray.length + 1);
  MediaType mediaType=null;
  if (direction != MediaDirection.SENDRECV)   mediaAttributes.add(createDirectionAttribute(direction));
  for (int i=0; i < payloadTypesArray.length; i++) {
    MediaFormat format=formats.get(i);
    MediaType fmtMediaType=format.getMediaType();
    if (mediaType == null) {
      mediaType=fmtMediaType;
    }
    byte payloadType=format.getRTPPayloadType();
    if (payloadType == MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN) {
      try {
        payloadType=dynamicPayloadTypes.obtainPayloadTypeNumber(format);
      }
 catch (      IllegalStateException exception) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INTERNAL_ERROR,exception);
      }
    }
    String numChannelsStr="String_Node_Str";
    if (format instanceof AudioMediaFormat) {
      int channels=((AudioMediaFormat)format).getChannels();
      if (channels > 1)       numChannelsStr="String_Node_Str" + channels;
    }
    Attribute rtpmap=sdpFactory.createAttribute(SdpConstants.RTPMAP,payloadType + "String_Node_Str" + format.getEncoding()+ "String_Node_Str"+ format.getClockRateString()+ numChannelsStr);
    mediaAttributes.add(rtpmap);
    if (format.getFormatParameters().size() > 0) {
      Attribute fmtp=sdpFactory.createAttribute("String_Node_Str",payloadType + "String_Node_Str" + encodeFmtp(format));
      mediaAttributes.add(fmtp);
    }
    Iterator<Map.Entry<String,String>> iter=format.getAdvancedAttributes().entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<String,String> ntry=iter.next();
      Attribute adv=sdpFactory.createAttribute(ntry.getKey(),payloadType + "String_Node_Str" + ntry.getValue());
      mediaAttributes.add(adv);
    }
    payloadTypesArray[i]=payloadType;
  }
  int rtpPort=connector.getDataSocket().getLocalPort();
  int rtcpPort=connector.getControlSocket().getLocalPort();
  if ((rtpPort + 1) != rtcpPort) {
    Attribute rtcpAttr=sdpFactory.createAttribute(RTCP_ATTR,Integer.toString(rtcpPort));
    mediaAttributes.add(rtcpAttr);
  }
  if (rtpExtensions != null && rtpExtensions.size() > 0) {
    for (    RTPExtension extension : rtpExtensions) {
      byte extID=rtpExtensionsRegistry.obtainExtensionMapping(extension);
      String uri=extension.getURI().toString();
      MediaDirection extDirection=extension.getDirection();
      String attributes=extension.getExtensionAttributes();
      String attrValue=Byte.toString(extID) + ((extDirection == MediaDirection.SENDRECV) ? "String_Node_Str" : ("String_Node_Str" + extDirection.toString())) + "String_Node_Str"+ uri+ (attributes == null ? "String_Node_Str" : ("String_Node_Str" + attributes));
      Attribute extMapAttr=sdpFactory.createAttribute(EXTMAP_ATTR,attrValue);
      mediaAttributes.add(extMapAttr);
    }
  }
  MediaDescription mediaDesc=null;
  try {
    mediaDesc=sdpFactory.createMediaDescription(mediaType.toString(),connector.getDataSocket().getLocalPort(),1,SdpConstants.RTP_AVP,payloadTypesArray);
    mediaDesc.setAttributes(mediaAttributes);
  }
 catch (  Exception cause) {
    ProtocolProviderServiceSipImpl.throwOperationFailedException("String_Node_Str",OperationFailedException.INTERNAL_ERROR,cause,logger);
  }
  return mediaDesc;
}

Fixed version (ground truth):
/** 
 * Creates a new <tt>MediaDescription</tt> instance according to the specified <tt>formats</tt>, <tt>connector</tt> and <tt>direction</tt>, and using the <tt>dynamicPayloadTypes</tt> registry to handle dynamic payload type registrations. The type (e.g. audio/video) of the media description is determined via from the type of the first <tt>MediaFormat</tt> in the <tt>formats</tt> list.
 * @param formats the list of formats that should be advertised in the newlycreated <tt>MediaDescription</tt>.
 * @param connector the socket couple that will be used for the media streamwhich we are advertising with the media description created here.
 * @param direction the direction of the media stream that we are describinghere.
 * @param rtpExtensions a list of <tt>RTPExtension</tt>s supported by the<tt>MediaDevice</tt> that we will be advertising.
 * @param dynamicPayloadTypes a reference to the<tt>DynamicPayloadTypeRegistry</tt> that we should be using to lookup and register dynamic RTP mappings.
 * @param rtpExtensionsRegistry a reference to the<tt>DynamicRTPExtensionRegistry</tt> that we should be using to lookup and register URN to ID mappings.
 * @return the newly create SDP <tt>MediaDescription</tt>.
 * @throws OperationFailedException in case we fail to get payload typenumbers for dynamic payload types or in case our SDP generation fails for some other reason.
 */
public static MediaDescription createMediaDescription(List<MediaFormat> formats,StreamConnector connector,MediaDirection direction,List<RTPExtension> rtpExtensions,DynamicPayloadTypeRegistry dynamicPayloadTypes,DynamicRTPExtensionsRegistry rtpExtensionsRegistry) throws OperationFailedException {
  int[] payloadTypesArray=new int[formats.size()];
  Vector<Attribute> mediaAttributes=new Vector<Attribute>(2 * payloadTypesArray.length + 1);
  MediaType mediaType=null;
  if (direction != MediaDirection.SENDRECV)   mediaAttributes.add(createDirectionAttribute(direction));
  for (int i=0; i < payloadTypesArray.length; i++) {
    MediaFormat format=formats.get(i);
    MediaType fmtMediaType=format.getMediaType();
    if (mediaType == null)     mediaType=fmtMediaType;
    byte payloadType=format.getRTPPayloadType();
    if (payloadType == MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN) {
      try {
        payloadType=dynamicPayloadTypes.obtainPayloadTypeNumber(format);
      }
 catch (      IllegalStateException exception) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INTERNAL_ERROR,exception);
      }
    }
    String numChannelsStr="String_Node_Str";
    if (format instanceof AudioMediaFormat) {
      int channels=((AudioMediaFormat)format).getChannels();
      if (channels > 1)       numChannelsStr="String_Node_Str" + channels;
    }
    Attribute rtpmap=sdpFactory.createAttribute(SdpConstants.RTPMAP,payloadType + "String_Node_Str" + format.getEncoding()+ "String_Node_Str"+ format.getClockRateString()+ numChannelsStr);
    mediaAttributes.add(rtpmap);
    if (format.getFormatParameters().size() > 0) {
      Attribute fmtp=sdpFactory.createAttribute("String_Node_Str",payloadType + "String_Node_Str" + encodeFmtp(format));
      mediaAttributes.add(fmtp);
    }
    Iterator<Map.Entry<String,String>> iter=format.getAdvancedAttributes().entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry<String,String> ntry=iter.next();
      Attribute adv=sdpFactory.createAttribute(ntry.getKey(),payloadType + "String_Node_Str" + ntry.getValue());
      mediaAttributes.add(adv);
    }
    payloadTypesArray[i]=payloadType;
  }
  int rtpPort=connector.getDataSocket().getLocalPort();
  int rtcpPort=connector.getControlSocket().getLocalPort();
  if ((rtpPort + 1) != rtcpPort) {
    Attribute rtcpAttr=sdpFactory.createAttribute(RTCP_ATTR,Integer.toString(rtcpPort));
    mediaAttributes.add(rtcpAttr);
  }
  if (rtpExtensions != null && rtpExtensions.size() > 0) {
    for (    RTPExtension extension : rtpExtensions) {
      byte extID=rtpExtensionsRegistry.obtainExtensionMapping(extension);
      String uri=extension.getURI().toString();
      MediaDirection extDirection=extension.getDirection();
      String attributes=extension.getExtensionAttributes();
      String attrValue=Byte.toString(extID) + ((extDirection == MediaDirection.SENDRECV) ? "String_Node_Str" : ("String_Node_Str" + extDirection.toString())) + "String_Node_Str"+ uri+ (attributes == null ? "String_Node_Str" : ("String_Node_Str" + attributes));
      Attribute extMapAttr=sdpFactory.createAttribute(EXTMAP_ATTR,attrValue);
      mediaAttributes.add(extMapAttr);
    }
  }
  MediaDescription mediaDesc=null;
  try {
    mediaDesc=sdpFactory.createMediaDescription(mediaType.toString(),connector.getDataSocket().getLocalPort(),1,SdpConstants.RTP_AVP,payloadTypesArray);
    mediaDesc.setAttributes(mediaAttributes);
  }
 catch (  Exception cause) {
    ProtocolProviderServiceSipImpl.throwOperationFailedException("String_Node_Str",OperationFailedException.INTERNAL_ERROR,cause,logger);
  }
  return mediaDesc;
}