Program: 34372
Project: 34372
Buggy source:
/** 
 * Publish event, on the behalf of a device, to the IBM Watson IoT Platform. <br> This method will attempt to create a JSON obejct out of the payload
 * @param deviceType object of String which denotes deviceType 
 * @param deviceId object of String which denotes deviceId
 * @param event object of String which denotes event
 * @param data Payload data
 * @param format The message format
 * @param qos Quality of Service, in int - can have values 0,1,2
 * @return Whether the send was successful.
 */
public boolean publishCommand(String deviceType,String deviceId,String command,Object data,String format,int qos) throws Exception {
  if (!isConnected()) {
    return false;
  }
  final String METHOD="String_Node_Str";
  String topic="String_Node_Str" + deviceType + "String_Node_Str"+ deviceId+ "String_Node_Str"+ command+ "String_Node_Str"+ format;
  Object payload=null;
  MqttMessage msg=null;
  if (data == null) {
    data=new JsonObject();
  }
  if (data.getClass() == String.class) {
    payload=data;
    msg=new MqttMessage(payload.toString().getBytes(Charset.forName("String_Node_Str")));
  }
 else   if (data.getClass().getName().equals("String_Node_Str")) {
    msg=new MqttMessage((byte[])data);
    payload=Arrays.toString((byte[])data);
  }
 else {
    payload=(JsonObject)gson.toJsonTree(data);
    msg=new MqttMessage(payload.toString().getBytes(Charset.forName("String_Node_Str")));
  }
  LoggerUtility.fine(CLASS_NAME,METHOD,"String_Node_Str" + topic);
  LoggerUtility.fine(CLASS_NAME,METHOD,"String_Node_Str" + payload.toString());
  msg.setQos(qos);
  msg.setRetained(false);
  try {
    if (isConnected() && !isAutomaticReconnect()) {
      mqttAsyncClient.publish(topic,msg).waitForCompletion();
    }
 else {
      mqttAsyncClient.publish(topic,msg);
    }
  }
 catch (  MqttPersistenceException e) {
    e.printStackTrace();
    return false;
  }
catch (  MqttException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Publish event, on the behalf of a device, to the IBM Watson IoT Platform. <br> This method will attempt to create a JSON obejct out of the payload
 * @param deviceType object of String which denotes deviceType 
 * @param deviceId object of String which denotes deviceId
 * @param command object of String which denotes the command
 * @param data Payload data
 * @param format The message format
 * @param qos Quality of Service, in int - can have values 0,1,2
 * @return Whether the send was successful.
 * @throws Exception when the publish operation fails
 */
public boolean publishCommand(String deviceType,String deviceId,String command,Object data,String format,int qos) throws Exception {
  if (!isConnected()) {
    return false;
  }
  final String METHOD="String_Node_Str";
  String topic="String_Node_Str" + deviceType + "String_Node_Str"+ deviceId+ "String_Node_Str"+ command+ "String_Node_Str"+ format;
  Object payload=null;
  MqttMessage msg=null;
  if (data == null) {
    data=new JsonObject();
  }
  if (data.getClass() == String.class) {
    payload=data;
    msg=new MqttMessage(payload.toString().getBytes(Charset.forName("String_Node_Str")));
  }
 else   if (data.getClass().getName().equals("String_Node_Str")) {
    msg=new MqttMessage((byte[])data);
    payload=Arrays.toString((byte[])data);
  }
 else {
    payload=(JsonObject)gson.toJsonTree(data);
    msg=new MqttMessage(payload.toString().getBytes(Charset.forName("String_Node_Str")));
  }
  LoggerUtility.fine(CLASS_NAME,METHOD,"String_Node_Str" + topic);
  LoggerUtility.fine(CLASS_NAME,METHOD,"String_Node_Str" + payload.toString());
  msg.setQos(qos);
  msg.setRetained(false);
  try {
    if (isConnected() && !isAutomaticReconnect()) {
      mqttAsyncClient.publish(topic,msg).waitForCompletion();
    }
 else {
      mqttAsyncClient.publish(topic,msg);
    }
  }
 catch (  MqttPersistenceException e) {
    e.printStackTrace();
    return false;
  }
catch (  MqttException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}