Program: 105063
Project: 105063
Buggy source:
/** 
 * Opens new WebRTC data channel using specified parameters.
 * @param type channel type as defined in control protocol description.Use 0 for "realiable".
 * @param prio channel priority. The higher the number, the lowerthe priority.
 * @param reliab Reliability Parameter<br/>This field is ignored if a reliable channel is used. If a partial reliable channel with limited number of retransmissions is used, this field specifies the number of retransmissions.  If a partial reliable channel with limited lifetime is used, this field specifies the maximum lifetime in milliseconds.  The following table summarizes this:<br/></br> +------------------------------------------------+------------------+ | Channel Type                                   |   Reliability    | |                                                |    Parameter     | +------------------------------------------------+------------------+ | DATA_CHANNEL_RELIABLE                          |     Ignored      | | DATA_CHANNEL_RELIABLE_UNORDERED                |     Ignored      | | DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT           |  Number of RTX   | | DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED |  Number of RTX   | | DATA_CHANNEL_PARTIAL_RELIABLE_TIMED            |  Lifetime in ms  | | DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED  |  Lifetime in ms  | +------------------------------------------------+------------------+
 * @param sid SCTP stream id that will be used by new channel(it must not be already used).
 * @param label text label for the channel.
 * @return new instance of <tt>WebRtcDataStream</tt> that represents openedWebRTC data channel.
 * @throws IOException if IO error occurs.
 */
public synchronized WebRtcDataStream openChannel(int type,int prio,long reliab,int sid,String label) throws IOException {
  if (channels.containsKey(sid)) {
    throw new IOException("String_Node_Str" + sid + "String_Node_Str");
  }
  ByteBuffer packet=ByteBuffer.allocate(14 + label.length());
  packet.put((byte)MSG_OPEN_CHANNEL);
  packet.put((byte)type);
  packet.putShort((short)prio);
  packet.putInt((int)reliab);
  packet.putShort((short)label.length());
  packet.putShort((short)0);
  if (label.length() > 0) {
    packet.put(label.getBytes("String_Node_Str"));
  }
  int sentCount=sctpSocket.send(packet.array(),true,sid,WEB_RTC_PPID_CTRL);
  if (sentCount != packet.capacity()) {
    throw new IOException("String_Node_Str" + sid);
  }
  WebRtcDataStream channel=new WebRtcDataStream(sctpSocket,sid,label,false);
  channels.put(sid,channel);
  return channel;
}

Fixed version (ground truth):
/** 
 * Opens new WebRTC data channel using specified parameters.
 * @param type channel type as defined in control protocol description.Use 0 for "realiable".
 * @param prio channel priority. The higher the number, the lowerthe priority.
 * @param reliab Reliability Parameter<br/>This field is ignored if a reliable channel is used. If a partial reliable channel with limited number of retransmissions is used, this field specifies the number of retransmissions.  If a partial reliable channel with limited lifetime is used, this field specifies the maximum lifetime in milliseconds.  The following table summarizes this:<br/></br> +------------------------------------------------+------------------+ | Channel Type                                   |   Reliability    | |                                                |    Parameter     | +------------------------------------------------+------------------+ | DATA_CHANNEL_RELIABLE                          |     Ignored      | | DATA_CHANNEL_RELIABLE_UNORDERED                |     Ignored      | | DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT           |  Number of RTX   | | DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED |  Number of RTX   | | DATA_CHANNEL_PARTIAL_RELIABLE_TIMED            |  Lifetime in ms  | | DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED  |  Lifetime in ms  | +------------------------------------------------+------------------+
 * @param sid SCTP stream id that will be used by new channel(it must not be already used).
 * @param label text label for the channel.
 * @return new instance of <tt>WebRtcDataStream</tt> that represents openedWebRTC data channel.
 * @throws IOException if IO error occurs.
 */
public synchronized WebRtcDataStream openChannel(int type,int prio,long reliab,int sid,String label) throws IOException {
  if (channels.containsKey(sid)) {
    throw new IOException("String_Node_Str" + sid + "String_Node_Str");
  }
  byte[] labelBytes;
  int labelByteLength;
  if (label == null) {
    labelBytes=null;
    labelByteLength=0;
  }
 else {
    labelBytes=label.getBytes("String_Node_Str");
    labelByteLength=labelBytes.length;
    if (labelByteLength > 0xFFFF)     labelByteLength=0xFFFF;
  }
  String protocol=WEBRTC_DATA_CHANNEL_PROTOCOL;
  byte[] protocolBytes;
  int protocolByteLength;
  if (protocol == null) {
    protocolBytes=null;
    protocolByteLength=0;
  }
 else {
    protocolBytes=protocol.getBytes("String_Node_Str");
    protocolByteLength=protocolBytes.length;
    if (protocolByteLength > 0xFFFF)     protocolByteLength=0xFFFF;
  }
  ByteBuffer packet=ByteBuffer.allocate(12 + labelByteLength + protocolByteLength);
  packet.put((byte)MSG_OPEN_CHANNEL);
  packet.put((byte)type);
  packet.putShort((short)prio);
  packet.putInt((int)reliab);
  packet.putShort((short)labelByteLength);
  packet.putShort((short)protocolByteLength);
  if (labelByteLength != 0) {
    packet.put(labelBytes,0,labelByteLength);
  }
  if (protocolByteLength != 0) {
    packet.put(protocolBytes,0,protocolByteLength);
  }
  int sentCount=sctpSocket.send(packet.array(),true,sid,WEB_RTC_PPID_CTRL);
  if (sentCount != packet.capacity()) {
    throw new IOException("String_Node_Str" + sid);
  }
  WebRtcDataStream channel=new WebRtcDataStream(sctpSocket,sid,label,false);
  channels.put(sid,channel);
  return channel;
}