Program: 103209
Project: 103209
Buggy source:
/** 
 * Allocates cobri (conference) channels for asp ecific <tt>MediaType</tt> to be used by a specific <tt>CallPeer</tt>.
 * @param peer the <tt>CallPeer</tt> which is to use the allocated cobri(conference) channels
 * @param mediaTypes the <tt>MediaType</tt>s for which cobri (conference)channels are to be allocated
 * @return a <tt>CobriConferenceIQ</tt> which describes the allocated cobri(conference) channels for the specified <tt>mediaTypes</tt> which are to be used by the specified <tt>peer</tt>; otherwise, <tt>null</tt>
 */
public CobriConferenceIQ createCobriChannels(CallPeerJabberImpl peer,Iterable<MediaType> mediaTypes){
  if (!isConferenceFocus())   return null;
  CallPeerMediaHandler<?> peerMediaHandler=peer.getMediaHandler();
  if (peerMediaHandler.getMediaHandler() != cobriMediaHandler) {
    for (    MediaType mediaType : MediaType.values())     if (peerMediaHandler.getStream(mediaType) != null)     return null;
  }
  ProtocolProviderServiceJabberImpl protocolProvider=getProtocolProvider();
  String jitsiVideoBridge=(cobri == null) ? protocolProvider.getJitsiVideoBridge() : cobri.getFrom();
  if ((jitsiVideoBridge == null) || (jitsiVideoBridge.length() == 0))   return null;
  CobriConferenceIQ conferenceRequest=new CobriConferenceIQ();
  if (cobri != null)   conferenceRequest.setID(cobri.getID());
  for (  MediaType mediaType : mediaTypes) {
    String contentName=mediaType.toString();
    CobriConferenceIQ.Content contentRequest=new CobriConferenceIQ.Content(contentName);
    conferenceRequest.addContent(contentRequest);
    boolean requestLocalChannel=true;
    if (cobri != null) {
      CobriConferenceIQ.Content content=cobri.getContent(contentName);
      if ((content != null) && (content.getChannelCount() > 0))       requestLocalChannel=false;
    }
    if (requestLocalChannel) {
      CobriConferenceIQ.Channel localChannelRequest=new CobriConferenceIQ.Channel();
      contentRequest.addChannel(localChannelRequest);
    }
    CobriConferenceIQ.Channel remoteChannelRequest=new CobriConferenceIQ.Channel();
    contentRequest.addChannel(remoteChannelRequest);
  }
  XMPPConnection connection=protocolProvider.getConnection();
  PacketCollector packetCollector=connection.createPacketCollector(new PacketIDFilter(conferenceRequest.getPacketID()));
  conferenceRequest.setTo(jitsiVideoBridge);
  conferenceRequest.setType(IQ.Type.GET);
  connection.sendPacket(conferenceRequest);
  Packet response=packetCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
  packetCollector.cancel();
  if ((response == null) || (response.getError() != null) || !(response instanceof CobriConferenceIQ))   return null;
  CobriConferenceIQ conferenceResponse=(CobriConferenceIQ)response;
  String conferenceResponseID=conferenceResponse.getID();
  if (cobri == null) {
    cobri=conferenceResponse;
  }
 else {
    String cobriID=cobri.getID();
    if (cobriID == null)     cobri.setID(conferenceResponseID);
 else     if (!cobriID.equals(conferenceResponseID))     throw new IllegalStateException("String_Node_Str");
    for (    CobriConferenceIQ.Content contentResponse : conferenceResponse.getContents()) {
      CobriConferenceIQ.Content content=cobri.getOrCreateContent(contentResponse.getName());
      for (      CobriConferenceIQ.Channel channelResponse : contentResponse.getChannels())       content.addChannel(channelResponse);
    }
  }
  CobriConferenceIQ conferenceResult=new CobriConferenceIQ();
  conferenceResult.setID(conferenceResponseID);
  for (  MediaType mediaType : mediaTypes) {
    CobriConferenceIQ.Content contentResponse=conferenceResponse.getContent(mediaType.toString());
    if (contentResponse != null) {
      String contentName=contentResponse.getName();
      CobriConferenceIQ.Content contentResult=new CobriConferenceIQ.Content(contentName);
      conferenceResult.addContent(contentResult);
      CobriConferenceIQ.Content content=cobri.getContent(contentName);
      CobriConferenceIQ.Channel localChannel=null;
      if ((content != null) && (content.getChannelCount() > 0)) {
        localChannel=content.getChannel(0);
        contentResult.addChannel(localChannel);
      }
      String localChannelID=(localChannel == null) ? null : localChannel.getID();
      for (      CobriConferenceIQ.Channel channelResponse : contentResponse.getChannels()) {
        if ((localChannelID == null) || !localChannelID.equals(channelResponse.getID()))         contentResult.addChannel(channelResponse);
      }
    }
  }
  if (cobriMediaHandler == null)   cobriMediaHandler=new MediaHandler();
  peerMediaHandler.setMediaHandler(cobriMediaHandler);
  return conferenceResult;
}

Fixed version (ground truth):
/** 
 * Allocates cobri (conference) channels for a specific <tt>MediaType</tt> to be used by a specific <tt>CallPeer</tt>.
 * @param peer the <tt>CallPeer</tt> which is to use the allocated cobri(conference) channels
 * @param rdpes the <tt>RtpDescriptionPacketExtension</tt>s which specifythe <tt>MediaType</tt>s for which cobri (conference) channels are to be allocated
 * @return a <tt>CobriConferenceIQ</tt> which describes the allocated cobri(conference) channels for the specified <tt>mediaTypes</tt> which are to be used by the specified <tt>peer</tt>; otherwise, <tt>null</tt>
 */
public CobriConferenceIQ createCobriChannels(CallPeerJabberImpl peer,Iterable<RtpDescriptionPacketExtension> rdpes){
  if (!isConferenceFocus())   return null;
  CallPeerMediaHandler<?> peerMediaHandler=peer.getMediaHandler();
  if (peerMediaHandler.getMediaHandler() != cobriMediaHandler) {
    for (    MediaType mediaType : MediaType.values())     if (peerMediaHandler.getStream(mediaType) != null)     return null;
  }
  ProtocolProviderServiceJabberImpl protocolProvider=getProtocolProvider();
  String jitsiVideoBridge=(cobri == null) ? protocolProvider.getJitsiVideoBridge() : cobri.getFrom();
  if ((jitsiVideoBridge == null) || (jitsiVideoBridge.length() == 0))   return null;
  CobriConferenceIQ conferenceRequest=new CobriConferenceIQ();
  if (cobri != null)   conferenceRequest.setID(cobri.getID());
  for (  RtpDescriptionPacketExtension rdpe : rdpes) {
    MediaType mediaType=MediaType.parseString(rdpe.getMedia());
    String contentName=mediaType.toString();
    CobriConferenceIQ.Content contentRequest=new CobriConferenceIQ.Content(contentName);
    conferenceRequest.addContent(contentRequest);
    boolean requestLocalChannel=true;
    if (cobri != null) {
      CobriConferenceIQ.Content content=cobri.getContent(contentName);
      if ((content != null) && (content.getChannelCount() > 0))       requestLocalChannel=false;
    }
    if (requestLocalChannel) {
      CobriConferenceIQ.Channel localChannelRequest=new CobriConferenceIQ.Channel();
      for (      PayloadTypePacketExtension ptpe : rdpe.getPayloadTypes())       localChannelRequest.addPayloadType(ptpe);
      contentRequest.addChannel(localChannelRequest);
    }
    CobriConferenceIQ.Channel remoteChannelRequest=new CobriConferenceIQ.Channel();
    for (    PayloadTypePacketExtension ptpe : rdpe.getPayloadTypes())     remoteChannelRequest.addPayloadType(ptpe);
    contentRequest.addChannel(remoteChannelRequest);
  }
  XMPPConnection connection=protocolProvider.getConnection();
  PacketCollector packetCollector=connection.createPacketCollector(new PacketIDFilter(conferenceRequest.getPacketID()));
  conferenceRequest.setTo(jitsiVideoBridge);
  conferenceRequest.setType(IQ.Type.GET);
  connection.sendPacket(conferenceRequest);
  Packet response=packetCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
  packetCollector.cancel();
  if ((response == null) || (response.getError() != null) || !(response instanceof CobriConferenceIQ))   return null;
  CobriConferenceIQ conferenceResponse=(CobriConferenceIQ)response;
  String conferenceResponseID=conferenceResponse.getID();
  if (cobri == null) {
    cobri=conferenceResponse;
  }
 else {
    String cobriID=cobri.getID();
    if (cobriID == null)     cobri.setID(conferenceResponseID);
 else     if (!cobriID.equals(conferenceResponseID))     throw new IllegalStateException("String_Node_Str");
    for (    CobriConferenceIQ.Content contentResponse : conferenceResponse.getContents()) {
      CobriConferenceIQ.Content content=cobri.getOrCreateContent(contentResponse.getName());
      for (      CobriConferenceIQ.Channel channelResponse : contentResponse.getChannels())       content.addChannel(channelResponse);
    }
  }
  CobriConferenceIQ conferenceResult=new CobriConferenceIQ();
  conferenceResult.setID(conferenceResponseID);
  for (  RtpDescriptionPacketExtension rdpe : rdpes) {
    MediaType mediaType=MediaType.parseString(rdpe.getMedia());
    CobriConferenceIQ.Content contentResponse=conferenceResponse.getContent(mediaType.toString());
    if (contentResponse != null) {
      String contentName=contentResponse.getName();
      CobriConferenceIQ.Content contentResult=new CobriConferenceIQ.Content(contentName);
      conferenceResult.addContent(contentResult);
      CobriConferenceIQ.Content content=cobri.getContent(contentName);
      CobriConferenceIQ.Channel localChannel=null;
      if ((content != null) && (content.getChannelCount() > 0)) {
        localChannel=content.getChannel(0);
        contentResult.addChannel(localChannel);
      }
      String localChannelID=(localChannel == null) ? null : localChannel.getID();
      for (      CobriConferenceIQ.Channel channelResponse : contentResponse.getChannels()) {
        if ((localChannelID == null) || !localChannelID.equals(channelResponse.getID()))         contentResult.addChannel(channelResponse);
      }
    }
  }
  if (cobriMediaHandler == null)   cobriMediaHandler=new MediaHandler();
  peerMediaHandler.setMediaHandler(cobriMediaHandler);
  return conferenceResult;
}