nus-yam/ex-repair huggingface dataset:
Program: 27448
Project: 27448
Buggy source:
/** 
 * Flood the subscribers with the message to notify. MessageID is optional and should only used for QoS 1 and 2
 */
private void publish2Subscribers(String topic,AbstractMessage.QOSType qos,ByteBuffer message,boolean retain,Integer messageID){
  LOG.debug("String_Node_Str",topic);
  LOG.debug("String_Node_Str",new String(message.array()));
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",subscriptions.dumpTree());
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    if (qos.ordinal() > sub.getRequestedQos().ordinal()) {
      qos=sub.getRequestedQos();
    }
    LOG.debug("String_Node_Str",sub.getClientId(),sub.getTopic(),qos,sub.isActive());
    if (qos == AbstractMessage.QOSType.MOST_ONE && sub.isActive()) {
      sendPublish(sub.getClientId(),topic,qos,message,false);
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
        m_storageService.storePublishForFuture(newPublishEvt);
      }
 else {
        if (qos == AbstractMessage.QOSType.EXACTLY_ONCE) {
          String publishKey=String.format("String_Node_Str",sub.getClientId(),messageID);
          PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
          m_storageService.addInFlight(newPublishEvt,publishKey);
        }
        if (sub.isActive()) {
          sendPublish(sub.getClientId(),topic,qos,message,false);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Flood the subscribers with the message to notify. MessageID is optional and should only used for QoS 1 and 2
 */
private void publish2Subscribers(String topic,AbstractMessage.QOSType qos,ByteBuffer message,boolean retain,Integer messageID){
  LOG.debug("String_Node_Str",topic);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",DebugUtils.payload2Str(message));
    LOG.debug("String_Node_Str",subscriptions.dumpTree());
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    if (qos.ordinal() > sub.getRequestedQos().ordinal()) {
      qos=sub.getRequestedQos();
    }
    message.rewind();
    LOG.debug("String_Node_Str",sub.getClientId(),sub.getTopic(),qos,sub.isActive());
    if (qos == AbstractMessage.QOSType.MOST_ONE && sub.isActive()) {
      sendPublish(sub.getClientId(),topic,qos,message,false);
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
        m_storageService.storePublishForFuture(newPublishEvt);
      }
 else {
        if (qos == AbstractMessage.QOSType.EXACTLY_ONCE) {
          String publishKey=String.format("String_Node_Str",sub.getClientId(),messageID);
          PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
          m_storageService.addInFlight(newPublishEvt,publishKey);
        }
        if (sub.isActive()) {
          sendPublish(sub.getClientId(),topic,qos,message,false);
        }
      }
    }
  }
}
Program: 27449
Project: 27449
Buggy source:
@Test public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertEquals("String_Node_Str",m_callback.getTopic());
  m_client.unsubscribe("String_Node_Str");
  m_callback.reinit();
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage());
}

Fixed version (ground truth):
@Test public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertEquals("String_Node_Str",m_callback.getTopic());
  m_client.unsubscribe("String_Node_Str");
  m_callback.reinit();
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage(false));
}
Program: 27450
Project: 27450
Buggy source:
@Test public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertEquals("String_Node_Str",m_callback.getTopic());
  m_client.unsubscribe("String_Node_Str");
  m_client.disconnect();
  m_callback.reinit();
  m_client.connect(options);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage());
}

Fixed version (ground truth):
@Test public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertEquals("String_Node_Str",m_callback.getTopic());
  m_client.unsubscribe("String_Node_Str");
  m_client.disconnect();
  m_callback.reinit();
  m_client.connect(options);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage(false));
}
Program: 27451
Project: 27451
Buggy source:
@Test public void avoidMultipleNotificationsAfterMultipleReconnection_cleanSessionFalseQoS1() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}

Fixed version (ground truth):
@Test public void avoidMultipleNotificationsAfterMultipleReconnection_cleanSessionFalseQoS1() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  MqttMessage message=m_callback.getMessage(true);
  assertNotNull(message);
  assertEquals("String_Node_Str",message.toString());
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  message=m_callback.getMessage(true);
  assertNotNull(message);
  assertEquals("String_Node_Str",message.toString());
}
Program: 27452
Project: 27452
Buggy source:
@Test public void testPublishWithQoS1_notCleanSession() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_client.connect(options);
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}

Fixed version (ground truth):
@Test public void testPublishWithQoS1_notCleanSession() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  m_client.connect(options);
  assertEquals("String_Node_Str",m_callback.getMessage(true).toString());
}
Program: 27453
Project: 27453
Buggy source:
@Test public void testPublishWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
  assertEquals(2,m_callback.getMessage().getQos());
}

Fixed version (ground truth):
@Test public void testPublishWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  MqttMessage message=m_callback.getMessage(true);
  assertEquals("String_Node_Str",message.toString());
  assertEquals(2,message.getQos());
}
Program: 27454
Project: 27454
Buggy source:
@Before public void setUp() throws Exception {
  startServer();
  m_client=new MqttClient("String_Node_Str","String_Node_Str",s_dataStore);
  m_callback=new TestCallback();
  m_client.setCallback(m_callback);
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  File dbFile=new File(Server.STORAGE_FILE_PATH);
  assertFalse(dbFile.exists());
  startServer();
  m_client=new MqttClient("String_Node_Str","String_Node_Str",s_dataStore);
  m_callback=new TestCallback();
  m_client.setCallback(m_callback);
}
Program: 27455
Project: 27455
Buggy source:
public MqttMessage getMessage(){
  try {
    m_latch.await(1,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
  return m_message;
}

Fixed version (ground truth):
public MqttMessage getMessage(boolean checkElapsed){
  try {
    boolean elapsed=!m_latch.await(1,TimeUnit.SECONDS);
    if (elapsed && checkElapsed) {
      throw new IllegalStateException("String_Node_Str");
    }
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
  return m_message;
}
Program: 27456
Project: 27456
Buggy source:
/** 
 * Check that after a client has connected with clean session false, subscribed to some topic and exited, if it reconnect with clean session true, the m_server correctly cleanup every previous subscription
 */
@Test public void testCleanSession_correctlyClientSubscriptions() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.disconnect();
  m_client.connect();
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage());
}

Fixed version (ground truth):
/** 
 * Check that after a client has connected with clean session false, subscribed to some topic and exited, if it reconnect with clean session true, the m_server correctly cleanup every previous subscription
 */
@Test public void testCleanSession_correctlyClientSubscriptions() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",0);
  m_client.disconnect();
  m_client.connect();
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),0,false);
  assertNull(m_callback.getMessage(false));
}
Program: 27457
Project: 27457
Buggy source:
@After public void tearDown() throws Exception {
  if (m_client.isConnected()) {
    m_client.disconnect();
  }
  m_server.stopServer();
  File dbFile=new File(Server.STORAGE_FILE_PATH);
  if (dbFile.exists()) {
    dbFile.delete();
  }
}

Fixed version (ground truth):
@After public void tearDown() throws Exception {
  if (m_client.isConnected()) {
    m_client.disconnect();
  }
  m_server.stopServer();
  File dbFile=new File(Server.STORAGE_FILE_PATH);
  if (dbFile.exists()) {
    dbFile.delete();
  }
  assertFalse(dbFile.exists());
}
Program: 27458
Project: 27458
Buggy source:
@Test public void testPublishWithQoS1() throws Exception {
  LOG.info("String_Node_Str");
  m_client.connect();
  m_client.subscribe("String_Node_Str",1);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),1,false);
  m_client.disconnect();
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
  assertEquals(1,m_callback.getMessage().getQos());
}

Fixed version (ground truth):
@Test public void testPublishWithQoS1() throws Exception {
  LOG.info("String_Node_Str");
  m_client.connect();
  m_client.subscribe("String_Node_Str",1);
  m_client.publish("String_Node_Str","String_Node_Str".getBytes(),1,false);
  m_client.disconnect();
  MqttMessage message=m_callback.getMessage(true);
  assertEquals("String_Node_Str",message.toString());
  assertEquals(1,message.getQos());
}
Program: 27459
Project: 27459
Buggy source:
@Test public void checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}

Fixed version (ground truth):
@Test public void checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  m_client.disconnect();
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",1);
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),1);
  MqttMessage message=m_callback.getMessage(true);
  assertNotNull(message);
  assertEquals("String_Node_Str",message.toString());
}
Program: 27460
Project: 27460
Buggy source:
@Test public void testPublishReceiveWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}

Fixed version (ground truth):
@Test public void testPublishReceiveWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  MqttMessage message=m_callback.getMessage(true);
  assertNotNull(message);
  assertEquals("String_Node_Str",message.toString());
}
Program: 27461
Project: 27461
Buggy source:
@Test public void testPublishWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_client.connect(options);
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
  assertEquals(2,m_callback.getMessage().getQos());
}

Fixed version (ground truth):
@Test public void testPublishWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
  assertEquals(2,m_callback.getMessage().getQos());
}
Program: 27462
Project: 27462
Buggy source:
@Test public void testPublishReceiveWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_client.connect(options);
  assertNotNull(m_callback);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}

Fixed version (ground truth):
@Test public void testPublishReceiveWithQoS2() throws Exception {
  LOG.info("String_Node_Str");
  MqttConnectOptions options=new MqttConnectOptions();
  options.setCleanSession(false);
  m_client.connect(options);
  m_client.subscribe("String_Node_Str",2);
  m_client.disconnect();
  publishFromAnotherClient("String_Node_Str","String_Node_Str".getBytes(),2);
  m_callback.reinit();
  m_client.connect(options);
  assertNotNull(m_callback);
  assertNotNull(m_callback.getMessage());
  assertEquals("String_Node_Str",m_callback.getMessage().toString());
}
Program: 27464
Project: 27464
Buggy source:
@Override public void write(Object value){
  try {
    System.out.println("String_Node_Str" + value.getClass().getName());
    if (value instanceof PublishMessage) {
      m_receivedMessage=(AbstractMessage)value;
    }
    if (m_receivedMessage instanceof ConnAckMessage) {
      ConnAckMessage buf=(ConnAckMessage)m_receivedMessage;
      m_returnCode=buf.getReturnCode();
    }
  }
 catch (  Exception ex) {
    throw new AssertionError("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void write(Object value){
  try {
    System.out.println("String_Node_Str" + value.getClass().getName());
    if (value instanceof PublishMessage) {
      m_receivedMessage=(AbstractMessage)value;
      publishRecvSignal.countDown();
    }
    if (m_receivedMessage instanceof ConnAckMessage) {
      ConnAckMessage buf=(ConnAckMessage)m_receivedMessage;
      m_returnCode=buf.getReturnCode();
    }
  }
 catch (  Exception ex) {
    throw new AssertionError("String_Node_Str");
  }
}
Program: 27465
Project: 27465
Buggy source:
/** 
 * Flood the subscribers with the message to notify. MessageID is optional and should only used for QoS 1 and 2
 */
private void publish2Subscribers(String topic,AbstractMessage.QOSType qos,ByteBuffer message,boolean retain,Integer messageID){
  LOG.debug("String_Node_Str",topic);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",subscriptions.dumpTree());
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    LOG.debug("String_Node_Str",sub.getClientId(),sub.getTopic(),qos,sub.isActive());
    if (qos == AbstractMessage.QOSType.MOST_ONE) {
      sendPublish(sub.getClientId(),topic,qos,message,false);
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
        m_storageService.storePublishForFuture(newPublishEvt);
      }
 else {
        if (qos == AbstractMessage.QOSType.EXACTLY_ONCE) {
          String publishKey=String.format("String_Node_Str",sub.getClientId(),messageID);
          PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
          m_storageService.addInFlight(newPublishEvt,publishKey);
        }
        sendPublish(sub.getClientId(),topic,qos,message,false);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Flood the subscribers with the message to notify. MessageID is optional and should only used for QoS 1 and 2
 */
private void publish2Subscribers(String topic,AbstractMessage.QOSType qos,ByteBuffer message,boolean retain,Integer messageID){
  LOG.debug("String_Node_Str",topic);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",subscriptions.dumpTree());
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    LOG.debug("String_Node_Str",sub.getClientId(),sub.getTopic(),qos,sub.isActive());
    if (qos == AbstractMessage.QOSType.MOST_ONE && sub.isActive()) {
      sendPublish(sub.getClientId(),topic,qos,message,false);
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
        m_storageService.storePublishForFuture(newPublishEvt);
      }
 else {
        if (qos == AbstractMessage.QOSType.EXACTLY_ONCE) {
          String publishKey=String.format("String_Node_Str",sub.getClientId(),messageID);
          PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),messageID,null);
          m_storageService.addInFlight(newPublishEvt,publishKey);
        }
        sendPublish(sub.getClientId(),topic,qos,message,false);
      }
    }
  }
}
Program: 27467
Project: 27467
Buggy source:
@Override void decode(ChannelHandlerContext ctx,ByteBuf in,List<Object> out) throws Exception {
  LOG.debug("String_Node_Str" + in);
  int startPos=in.readerIndex();
  in.resetReaderIndex();
  PublishMessage message=new PublishMessage();
  if (!decodeCommonHeader(message,in)) {
    LOG.info("String_Node_Str" + in);
    in.resetReaderIndex();
    return;
  }
  int remainingLength=message.getRemainingLength();
  String topic=Utils.decodeString(in);
  if (topic == null) {
    in.resetReaderIndex();
    return;
  }
  message.setTopicName(topic);
  if (message.getQos() == AbstractMessage.QOSType.LEAST_ONE || message.getQos() == AbstractMessage.QOSType.EXACTLY_ONCE) {
    message.setMessageID(in.readUnsignedShort());
  }
  int stopPos=in.readerIndex();
  int payloadSize=remainingLength - (stopPos - startPos - 2) + (Utils.numBytesToEncode(remainingLength) - 1);
  if (in.readableBytes() < payloadSize) {
    in.resetReaderIndex();
    return;
  }
  byte[] b=new byte[payloadSize];
  in.readBytes(b);
  message.setPayload(b);
  out.add(message);
}

Fixed version (ground truth):
@Override void decode(ChannelHandlerContext ctx,ByteBuf in,List<Object> out) throws Exception {
  LOG.info("String_Node_Str" + in);
  in.resetReaderIndex();
  int startPos=in.readerIndex();
  PublishMessage message=new PublishMessage();
  if (!decodeCommonHeader(message,in)) {
    LOG.info("String_Node_Str" + in);
    in.resetReaderIndex();
    return;
  }
  int remainingLength=message.getRemainingLength();
  String topic=Utils.decodeString(in);
  if (topic == null) {
    in.resetReaderIndex();
    return;
  }
  message.setTopicName(topic);
  if (message.getQos() == AbstractMessage.QOSType.LEAST_ONE || message.getQos() == AbstractMessage.QOSType.EXACTLY_ONCE) {
    message.setMessageID(in.readUnsignedShort());
  }
  int stopPos=in.readerIndex();
  int payloadSize=remainingLength - (stopPos - startPos - 2) + (Utils.numBytesToEncode(remainingLength) - 1);
  if (in.readableBytes() < payloadSize) {
    in.resetReaderIndex();
    return;
  }
  byte[] b=new byte[payloadSize];
  in.readBytes(b);
  message.setPayload(b);
  out.add(message);
}
Program: 27468
Project: 27468
Buggy source:
public void storeRetained(String topic,byte[] message,AbstractMessage.QOSType qos){
  if (message.length == 0) {
    m_retainedStore.remove(topic);
  }
 else {
    m_retainedStore.put(topic,new StoredMessage(message,qos));
  }
}

Fixed version (ground truth):
public void storeRetained(String topic,byte[] message,AbstractMessage.QOSType qos){
  if (message.length == 0) {
    m_retainedStore.remove(topic);
  }
 else {
    m_retainedStore.put(topic,new StoredMessage(message,qos,topic));
  }
}
Program: 27469
Project: 27469
Buggy source:
StoredMessage(byte[] message,AbstractMessage.QOSType qos){
  m_qos=qos;
  m_payload=message;
}

Fixed version (ground truth):
StoredMessage(byte[] message,AbstractMessage.QOSType qos,String topic){
  m_qos=qos;
  m_payload=message;
  m_topic=topic;
}
Program: 27470
Project: 27470
Buggy source:
protected void processSubscribe(IoSession session,SubscribeMessage msg,String clientID,boolean cleanSession){
  LOG.debug("String_Node_Str");
  for (  SubscribeMessage.Couple req : msg.subscriptions()) {
    QOSType qos=AbstractMessage.QOSType.fromByte(req.getQos());
    Subscription newSubscription=new Subscription(clientID,req.getTopic(),qos,cleanSession);
    subscribeSingleTopic(newSubscription,req.getTopic());
  }
  SubAckMessage ackMessage=new SubAckMessage();
  ackMessage.setMessageID(msg.getMessageID());
  for (int i=0; i < msg.subscriptions().size(); i++) {
    ackMessage.addType(QOSType.MOST_ONE);
  }
  LOG.info("String_Node_Str" + msg.getMessageID());
  session.write(ackMessage);
}

Fixed version (ground truth):
protected void processSubscribe(IoSession session,SubscribeMessage msg,String clientID,boolean cleanSession){
  LOG.debug("String_Node_Str");
  for (  SubscribeMessage.Couple req : msg.subscriptions()) {
    QOSType qos=AbstractMessage.QOSType.values()[req.getQos()];
    Subscription newSubscription=new Subscription(clientID,req.getTopic(),qos,cleanSession);
    subscribeSingleTopic(newSubscription,req.getTopic());
  }
  SubAckMessage ackMessage=new SubAckMessage();
  ackMessage.setMessageID(msg.getMessageID());
  for (int i=0; i < msg.subscriptions().size(); i++) {
    ackMessage.addType(QOSType.MOST_ONE);
  }
  LOG.info("String_Node_Str" + msg.getMessageID());
  session.write(ackMessage);
}
Program: 27471
Project: 27471
Buggy source:
private void subscribeSingleTopic(Subscription newSubscription,final String topic){
  subscriptions.add(newSubscription);
  Collection<StoredMessage> messages=m_storageService.searchMatching(new IMatchingCondition(){
    public boolean match(    String key){
      return SubscriptionsStore.matchTopics(key,topic);
    }
  }
);
  for (  StoredMessage storedMsg : messages) {
    LOG.debug("String_Node_Str" + topic);
    notify(new NotifyEvent(newSubscription.getClientId(),topic,storedMsg.getQos(),storedMsg.getPayload(),true));
  }
}

Fixed version (ground truth):
private void subscribeSingleTopic(Subscription newSubscription,final String topic){
  subscriptions.add(newSubscription);
  Collection<StoredMessage> messages=m_storageService.searchMatching(new IMatchingCondition(){
    public boolean match(    String key){
      return SubscriptionsStore.matchTopics(key,topic);
    }
  }
);
  for (  StoredMessage storedMsg : messages) {
    LOG.debug("String_Node_Str" + topic);
    notify(new NotifyEvent(newSubscription.getClientId(),storedMsg.getTopic(),storedMsg.getQos(),storedMsg.getPayload(),true));
  }
}
Program: 27472
Project: 27472
Buggy source:
@Override public void filterWrite(NextFilter nextFilter,IoSession session,WriteRequest writeRequest) throws Exception {
  try {
    m_receivedMessage=(AbstractMessage)writeRequest.getMessage();
    if (m_receivedMessage instanceof ConnAckMessage) {
      ConnAckMessage buf=(ConnAckMessage)m_receivedMessage;
      m_returnCode=buf.getReturnCode();
    }
  }
 catch (  Exception ex) {
    throw new AssertionError("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void filterWrite(IoFilter.NextFilter nextFilter,IoSession session,WriteRequest writeRequest) throws Exception {
  try {
    System.out.println("String_Node_Str" + writeRequest.getMessage().getClass().getName());
    if (writeRequest.getMessage() instanceof PublishMessage) {
      m_receivedMessage=(AbstractMessage)writeRequest.getMessage();
    }
    if (m_receivedMessage instanceof ConnAckMessage) {
      ConnAckMessage buf=(ConnAckMessage)m_receivedMessage;
      m_returnCode=buf.getReturnCode();
    }
  }
 catch (  Exception ex) {
    throw new AssertionError("String_Node_Str");
  }
}
Program: 27473
Project: 27473
Buggy source:
public void republishStored(String clientID){
  disruptorPublish(new RepublishEvent(clientID));
}

Fixed version (ground truth):
public void republishStored(String clientID){
  LOG.debug("String_Node_Str" + clientID);
  disruptorPublish(new RepublishEvent(clientID));
}
Program: 27474
Project: 27474
Buggy source:
protected void processPublish(PublishEvent evt){
  LOG.debug("String_Node_Str");
  final String topic=evt.getTopic();
  final QOSType qos=evt.getQos();
  final byte[] message=evt.getMessage();
  boolean retain=evt.isRetain();
  CleanInFlightEvent cleanEvt=null;
  if (qos == QOSType.LEAST_ONE) {
    String publishKey=String.format("String_Node_Str",evt.getClientID(),evt.getMessageID());
    m_storageService.addInFlight(evt,publishKey);
    cleanEvt=new CleanInFlightEvent(publishKey);
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    if (qos == QOSType.MOST_ONE) {
      notify(new NotifyEvent(sub.clientId,topic,qos,message,false));
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        m_storageService.storePublishForFuture(evt);
      }
      notify(new NotifyEvent(sub.clientId,topic,qos,message,false));
    }
  }
  if (cleanEvt != null) {
    refill(cleanEvt);
    sendPubAck(new PubAckEvent(evt.getMessageID(),evt.getClientID()));
  }
  if (retain) {
    m_storageService.storeRetained(topic,message,qos);
  }
}

Fixed version (ground truth):
protected void processPublish(PublishEvent evt){
  LOG.debug("String_Node_Str" + evt);
  final String topic=evt.getTopic();
  final QOSType qos=evt.getQos();
  final byte[] message=evt.getMessage();
  boolean retain=evt.isRetain();
  CleanInFlightEvent cleanEvt=null;
  if (qos == QOSType.LEAST_ONE) {
    String publishKey=String.format("String_Node_Str",evt.getClientID(),evt.getMessageID());
    m_storageService.addInFlight(evt,publishKey);
    cleanEvt=new CleanInFlightEvent(publishKey);
  }
  for (  final Subscription sub : subscriptions.matches(topic)) {
    if (qos == QOSType.MOST_ONE) {
      notify(new NotifyEvent(sub.clientId,topic,qos,message,false));
    }
 else {
      if (!sub.isCleanSession() && !sub.isActive()) {
        PublishEvent newPublishEvt=new PublishEvent(topic,qos,message,retain,sub.getClientId(),evt.getMessageID(),null);
        m_storageService.storePublishForFuture(newPublishEvt);
      }
 else {
        notify(new NotifyEvent(sub.clientId,topic,qos,message,false));
      }
    }
  }
  if (cleanEvt != null) {
    refill(cleanEvt);
    sendPubAck(new PubAckEvent(evt.getMessageID(),evt.getClientID()));
  }
  if (retain) {
    m_storageService.storeRetained(topic,message,qos);
  }
}
Program: 27475
Project: 27475
Buggy source:
protected void processSubscribe(IoSession session,SubscribeMessage msg,String clientID,boolean cleanSession){
  LOG.debug("String_Node_Str");
  for (  SubscribeMessage.Couple req : msg.subscriptions()) {
    QOSType qos=AbstractMessage.QOSType.values()[req.getQos()];
    Subscription newSubscription=new Subscription(clientID,req.getTopic(),qos,cleanSession);
    subscribeSingleTopic(newSubscription,req.getTopic());
  }
  SubAckMessage ackMessage=new SubAckMessage();
  ackMessage.setMessageID(msg.getMessageID());
  for (int i=0; i < msg.subscriptions().size(); i++) {
    ackMessage.addType(QOSType.MOST_ONE);
  }
  LOG.info("String_Node_Str",msg.getMessageID());
  session.write(ackMessage);
}

Fixed version (ground truth):
protected void processSubscribe(IoSession session,SubscribeMessage msg,String clientID,boolean cleanSession){
  LOG.debug("String_Node_Str");
  for (  SubscribeMessage.Couple req : msg.subscriptions()) {
    QOSType qos=AbstractMessage.QOSType.values()[req.getQos()];
    Subscription newSubscription=new Subscription(clientID,req.getTopic(),qos,cleanSession);
    subscribeSingleTopic(newSubscription,req.getTopic());
  }
  SubAckMessage ackMessage=new SubAckMessage();
  ackMessage.setMessageID(msg.getMessageID());
  for (int i=0; i < msg.subscriptions().size(); i++) {
    ackMessage.addType(QOSType.MOST_ONE);
    ackMessage.addType(QOSType.LEAST_ONE);
  }
  LOG.info("String_Node_Str" + msg.getMessageID());
  session.write(ackMessage);
}
Program: 27477
Project: 27477
Buggy source:
private void processRepublish(RepublishEvent evt) throws InterruptedException {
  List<PublishEvent> publishedEvents=m_storageService.retrivePersistedPublishes(evt.getClientID());
  if (publishedEvents == null) {
    return;
  }
  for (  PublishEvent pubEvt : publishedEvents) {
    notify(new NotifyEvent(pubEvt.getClientID(),pubEvt.getTopic(),pubEvt.getQos(),pubEvt.getMessage(),false,pubEvt.getMessageID()));
  }
}

Fixed version (ground truth):
private void processRepublish(RepublishEvent evt) throws InterruptedException {
  LOG.debug("String_Node_Str");
  List<PublishEvent> publishedEvents=m_storageService.retrivePersistedPublishes(evt.getClientID());
  if (publishedEvents == null) {
    LOG.debug("String_Node_Str");
    return;
  }
  for (  PublishEvent pubEvt : publishedEvents) {
    notify(new NotifyEvent(pubEvt.getClientID(),pubEvt.getTopic(),pubEvt.getQos(),pubEvt.getMessage(),false,pubEvt.getMessageID()));
  }
}
Program: 27479
Project: 27479
Buggy source:
public MessageDecoderResult decode(IoSession session,IoBuffer in,ProtocolDecoderOutput out) throws Exception {
  int startPos=in.position();
  PublishMessage message=new PublishMessage();
  if (decodeCommonHeader(message,in) == NEED_DATA) {
    return NEED_DATA;
  }
  int remainingLength=message.getRemainingLength();
  String topic=Utils.decodeString(in);
  if (topic == null) {
    return NEED_DATA;
  }
  message.setTopicName(topic);
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    message.setMessageID(Utils.readWord(in));
  }
  int stopPos=in.position();
  int payloadSize=remainingLength - (stopPos - startPos - 2);
  byte[] b=new byte[payloadSize];
  if (in.remaining() < payloadSize) {
    return NEED_DATA;
  }
  in.get(b);
  message.setPayload(b);
  out.write(message);
  return OK;
}

Fixed version (ground truth):
public MessageDecoderResult decode(IoSession session,IoBuffer in,ProtocolDecoderOutput out) throws Exception {
  LOG.debug("String_Node_Str" + in);
  int startPos=in.position();
  PublishMessage message=new PublishMessage();
  if (decodeCommonHeader(message,in) == NEED_DATA) {
    LOG.info("String_Node_Str" + in);
    return NEED_DATA;
  }
  int remainingLength=message.getRemainingLength();
  String topic=Utils.decodeString(in);
  if (topic == null) {
    return NEED_DATA;
  }
  message.setTopicName(topic);
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    message.setMessageID(Utils.readWord(in));
  }
  int stopPos=in.position();
  int payloadSize=remainingLength - (stopPos - startPos - 2) + (Utils.numBytesToEncode(remainingLength) - 1);
  if (in.remaining() < payloadSize) {
    return NEED_DATA;
  }
  byte[] b=new byte[payloadSize];
  in.get(b);
  message.setPayload(b);
  out.write(message);
  return OK;
}
Program: 27480
Project: 27480
Buggy source:
public void encode(IoSession session,PublishMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.getQos() == QOSType.RESERVED) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getTopicName() == null || message.getTopicName().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(2).setAutoExpand(true);
  variableHeaderBuff.put(Utils.encodeString(message.getTopicName()));
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    if (message.getMessageID() == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Utils.writeWord(variableHeaderBuff,message.getMessageID());
  }
  variableHeaderBuff.put(message.getPayload());
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(2 + variableHeaderSize);
  buff.put((byte)(AbstractMessage.PUBLISH << 4 | flags));
  buff.put(Utils.encodeRemainingLength(variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}

Fixed version (ground truth):
public void encode(IoSession session,PublishMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.getQos() == QOSType.RESERVED) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getTopicName() == null || message.getTopicName().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(2).setAutoExpand(true);
  variableHeaderBuff.put(Utils.encodeString(message.getTopicName()));
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    if (message.getMessageID() == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Utils.writeWord(variableHeaderBuff,message.getMessageID());
  }
  variableHeaderBuff.put(message.getPayload());
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(2 + variableHeaderSize).setAutoExpand(true);
  ;
  buff.put((byte)(AbstractMessage.PUBLISH << 4 | flags));
  buff.put(Utils.encodeRemainingLength(variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}
Program: 27481
Project: 27481
Buggy source:
public void encode(IoSession session,UnsubscribeMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.topics().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getQos() != QOSType.LEAST_ONE) {
    throw new IllegalArgumentException("String_Node_Str" + message.getQos());
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(4).setAutoExpand(true);
  Utils.writeWord(variableHeaderBuff,message.getMessageID());
  for (  String topic : message.topics()) {
    variableHeaderBuff.put(Utils.encodeString(topic));
  }
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(4 + variableHeaderSize);
  buff.put((byte)(AbstractMessage.UNSUBSCRIBE << 4 | flags));
  buff.put(Utils.encodeRemainingLength(4 + variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}

Fixed version (ground truth):
public void encode(IoSession session,UnsubscribeMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.topics().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getQos() != QOSType.LEAST_ONE) {
    throw new IllegalArgumentException("String_Node_Str" + message.getQos());
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(4).setAutoExpand(true);
  Utils.writeWord(variableHeaderBuff,message.getMessageID());
  for (  String topic : message.topics()) {
    variableHeaderBuff.put(Utils.encodeString(topic));
  }
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(2 + variableHeaderSize);
  buff.put((byte)(AbstractMessage.UNSUBSCRIBE << 4 | flags));
  buff.put(Utils.encodeRemainingLength(2 + variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}
Program: 27482
Project: 27482
Buggy source:
@Test public void testEncodeWithMultiTopic() throws Exception {
  m_msg.setQos(QOSType.LEAST_ONE);
  String topic1="String_Node_Str";
  String topic2="String_Node_Str";
  m_msg.addTopic(topic1);
  m_msg.addTopic(topic2);
  m_encoder.encode(null,m_msg,m_mockProtoEncoder);
  assertEquals((byte)0xA2,(byte)m_mockProtoEncoder.getBuffer().get());
  assertEquals(18,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xAA,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xBB,m_mockProtoEncoder.getBuffer().get());
  verifyString(topic1,m_mockProtoEncoder.getBuffer());
  verifyString(topic2,m_mockProtoEncoder.getBuffer());
}

Fixed version (ground truth):
@Test public void testEncodeWithMultiTopic() throws Exception {
  m_msg.setQos(QOSType.LEAST_ONE);
  String topic1="String_Node_Str";
  String topic2="String_Node_Str";
  m_msg.addTopic(topic1);
  m_msg.addTopic(topic2);
  m_encoder.encode(null,m_msg,m_mockProtoEncoder);
  assertEquals((byte)0xA2,(byte)m_mockProtoEncoder.getBuffer().get());
  assertEquals(16,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xAA,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xBB,m_mockProtoEncoder.getBuffer().get());
  verifyString(topic1,m_mockProtoEncoder.getBuffer());
  verifyString(topic2,m_mockProtoEncoder.getBuffer());
}
Program: 27483
Project: 27483
Buggy source:
static byte encodeFlags(AbstractMessage message){
  byte flags=0;
  if (message.isDupFlag()) {
    flags|=0x08;
  }
  flags|=((message.getQos().ordinal() & 0x03) << 1);
  return flags;
}

Fixed version (ground truth):
static byte encodeFlags(AbstractMessage message){
  byte flags=0;
  if (message.isDupFlag()) {
    flags|=0x08;
  }
  if (message.isRetainFlag()) {
    flags|=0x01;
  }
  flags|=((message.getQos().ordinal() & 0x03) << 1);
  return flags;
}
Program: 27484
Project: 27484
Buggy source:
public MessageDecoderResult decode(IoSession session,IoBuffer in,ProtocolDecoderOutput out) throws Exception {
  SubAckMessage message=new SubAckMessage();
  if (decodeCommonHeader(message,in) == NEED_DATA) {
    return NEED_DATA;
  }
  int remainingLength=message.getRemainingLength();
  message.setMessageID(Utils.readWord(in));
  if (in.remaining() < remainingLength) {
    return NEED_DATA;
  }
  for (int i=0; i < remainingLength; i++) {
    byte qos=in.get();
    message.addType(QOSType.values()[qos]);
  }
  out.write(message);
  return OK;
}

Fixed version (ground truth):
public MessageDecoderResult decode(IoSession session,IoBuffer in,ProtocolDecoderOutput out) throws Exception {
  SubAckMessage message=new SubAckMessage();
  if (decodeCommonHeader(message,in) == NEED_DATA) {
    return NEED_DATA;
  }
  int remainingLength=message.getRemainingLength();
  message.setMessageID(Utils.readWord(in));
  remainingLength-=2;
  if (in.remaining() < remainingLength) {
    return NEED_DATA;
  }
  for (int i=0; i < remainingLength; i++) {
    byte qos=in.get();
    message.addType(QOSType.values()[qos]);
  }
  out.write(message);
  return OK;
}
Program: 27485
Project: 27485
Buggy source:
private void initHeaderQos(IoBuffer buff,int messageID,QOSType... qoss) throws IllegalAccessException {
  buff.clear().put((byte)(AbstractMessage.SUBACK << 4)).put(Utils.encodeRemainingLength(3));
  Utils.writeWord(buff,messageID);
  for (  QOSType qos : qoss) {
    buff.put((byte)qos.ordinal());
  }
}

Fixed version (ground truth):
private void initHeaderQos(IoBuffer buff,int messageID,QOSType... qoss) throws IllegalAccessException {
  buff.clear().put((byte)(AbstractMessage.SUBACK << 4)).put(Utils.encodeRemainingLength(2 + qoss.length));
  Utils.writeWord(buff,messageID);
  for (  QOSType qos : qoss) {
    buff.put((byte)qos.ordinal());
  }
}
Program: 27486
Project: 27486
Buggy source:
@Test public void testEncodeWithMultiTopic() throws Exception {
  SubscribeMessage msg=new SubscribeMessage();
  msg.setQos(QOSType.LEAST_ONE);
  msg.setMessageID(0xAABB);
  Couple c1=new Couple((byte)1,"String_Node_Str");
  Couple c2=new Couple((byte)0,"String_Node_Str");
  msg.addSubscription(c1);
  msg.addSubscription(c2);
  m_encoder.encode(null,msg,m_mockProtoEncoder);
  assertEquals((byte)0x82,(byte)m_mockProtoEncoder.getBuffer().get());
  assertEquals(20,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xAA,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xBB,m_mockProtoEncoder.getBuffer().get());
  verifyString(c1.getTopic(),m_mockProtoEncoder.getBuffer());
  assertEquals(c1.getQos(),m_mockProtoEncoder.getBuffer().get());
  verifyString(c2.getTopic(),m_mockProtoEncoder.getBuffer());
  assertEquals(c2.getQos(),m_mockProtoEncoder.getBuffer().get());
}

Fixed version (ground truth):
@Test public void testEncodeWithMultiTopic() throws Exception {
  SubscribeMessage msg=new SubscribeMessage();
  msg.setQos(QOSType.LEAST_ONE);
  msg.setMessageID(0xAABB);
  Couple c1=new Couple((byte)1,"String_Node_Str");
  Couple c2=new Couple((byte)0,"String_Node_Str");
  msg.addSubscription(c1);
  msg.addSubscription(c2);
  m_encoder.encode(null,msg,m_mockProtoEncoder);
  assertEquals((byte)0x82,(byte)m_mockProtoEncoder.getBuffer().get());
  assertEquals(16,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xAA,m_mockProtoEncoder.getBuffer().get());
  assertEquals((byte)0xBB,m_mockProtoEncoder.getBuffer().get());
  verifyString(c1.getTopic(),m_mockProtoEncoder.getBuffer());
  assertEquals(c1.getQos(),m_mockProtoEncoder.getBuffer().get());
  verifyString(c2.getTopic(),m_mockProtoEncoder.getBuffer());
  assertEquals(c2.getQos(),m_mockProtoEncoder.getBuffer().get());
}
Program: 27487
Project: 27487
Buggy source:
public void encode(IoSession session,PublishMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.getQos() == QOSType.RESERVED) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getTopicName() == null || message.getTopicName().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(2).setAutoExpand(true);
  variableHeaderBuff.put(Utils.encodeString(message.getTopicName()));
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    if (message.getMessageID() == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Utils.writeWord(variableHeaderBuff,message.getMessageID());
  }
  variableHeaderBuff.put(message.getPayload());
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(4 + variableHeaderSize);
  buff.put((byte)(AbstractMessage.PUBLISH << 4 | flags));
  buff.put(Utils.encodeRemainingLength(4 + variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}

Fixed version (ground truth):
public void encode(IoSession session,PublishMessage message,ProtocolEncoderOutput out) throws Exception {
  if (message.getQos() == QOSType.RESERVED) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (message.getTopicName() == null || message.getTopicName().isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  IoBuffer variableHeaderBuff=IoBuffer.allocate(2).setAutoExpand(true);
  variableHeaderBuff.put(Utils.encodeString(message.getTopicName()));
  if (message.getQos() == QOSType.LEAST_ONE || message.getQos() == QOSType.EXACTLY_ONCE) {
    if (message.getMessageID() == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Utils.writeWord(variableHeaderBuff,message.getMessageID());
  }
  variableHeaderBuff.put(message.getPayload());
  variableHeaderBuff.flip();
  int variableHeaderSize=variableHeaderBuff.remaining();
  byte flags=Utils.encodeFlags(message);
  IoBuffer buff=IoBuffer.allocate(2 + variableHeaderSize);
  buff.put((byte)(AbstractMessage.PUBLISH << 4 | flags));
  buff.put(Utils.encodeRemainingLength(variableHeaderSize));
  buff.put(variableHeaderBuff).flip();
  out.write(buff);
}