Program: 34363
Project: 34363
Buggy source:
/** 
 * Call to the connectUsingCertificate() method is made, when the User chooses to connect to the Watson IoT Platform using Client Certificate as the preferred Authentication mechanism. The Device Properties file allows you enable either Token based or Certificate based or both mechanisms to authenticate. However, setting the value to either 'True' or 'False' against the parameter 'Use-Secure-Certificate', facilitates usage of Certificates for authentication or not, respectively. Setting the value of parameter 'Use-Secure-Certificate' to 'True' in the Device.Properties file will make a call to the following method. 
 */
private void connectUsingCertificate(){
  final String METHOD="String_Node_Str";
  String protocol=null;
  int port=getPortNumber();
  if (isWebSocket()) {
    protocol="String_Node_Str";
    if (port == -1) {
      port=WSS_PORT;
    }
  }
 else {
    protocol="String_Node_Str";
    if (port == -1) {
      port=MQTTS_PORT;
    }
  }
  String mqttServer=getMQTTServer();
  if (mqttServer != null) {
    serverURI=protocol + mqttServer + "String_Node_Str"+ port;
  }
 else {
    serverURI=protocol + getOrgId() + "String_Node_Str"+ MESSAGING+ "String_Node_Str"+ this.getDomain()+ "String_Node_Str"+ port;
  }
  try {
    mqttAsyncClient=new MqttAsyncClient(serverURI,clientId,DATA_STORE);
    mqttAsyncClient.setCallback(mqttCallback);
    mqttClientOptions=new MqttConnectOptions();
    if (clientUsername != null) {
      mqttClientOptions.setUserName(clientUsername);
    }
    if (clientPassword != null) {
      mqttClientOptions.setPassword(clientPassword.toCharArray());
    }
    mqttClientOptions.setCleanSession(this.isCleanSession());
    if (this.keepAliveInterval != -1) {
      mqttClientOptions.setKeepAliveInterval(this.keepAliveInterval);
    }
    mqttClientOptions.setMaxInflight(getMaxInflight());
    mqttClientOptions.setAutomaticReconnect(isAutomaticReconnect());
    SSLContext sslContext=SSLContext.getInstance("String_Node_Str");
    sslContext.init(null,null,null);
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        serverCert=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        return;
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
      return;
    }
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        clientCert=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        return;
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
      return;
    }
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        clientCertKey=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        return;
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
      return;
    }
    try {
      if (trimedValue(options.getProperty("String_Node_Str")) != null) {
        certPassword=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        certPassword="String_Node_Str";
      }
    }
 catch (    Exception e) {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str",e);
      e.printStackTrace();
      throw e;
    }
    mqttClientOptions.setSocketFactory(getSocketFactory(serverCert,clientCert,clientCertKey,certPassword));
  }
 catch (  Exception e) {
    LoggerUtility.warn(CLASS_NAME,METHOD,"String_Node_Str" + e.getMessage());
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * Call to the connectUsingCertificate() method is made, when the User chooses to connect to the Watson IoT Platform using Client Certificate as the preferred Authentication mechanism. The Device Properties file allows you enable either Token based or Certificate based or both mechanisms to authenticate. However, setting the value to either 'True' or 'False' against the parameter 'Use-Secure-Certificate', facilitates usage of Certificates for authentication or not, respectively. Setting the value of parameter 'Use-Secure-Certificate' to 'True' in the Device.Properties file will make a call to the following method. 
 */
private void connectUsingCertificate(){
  final String METHOD="String_Node_Str";
  String protocol=null;
  int port=getPortNumber();
  if (isWebSocket()) {
    protocol="String_Node_Str";
    if (port == -1) {
      port=WSS_PORT;
    }
  }
 else {
    protocol="String_Node_Str";
    if (port == -1) {
      port=MQTTS_PORT;
    }
  }
  String mqttServer=getMQTTServer();
  if (mqttServer != null) {
    serverURI=protocol + mqttServer + "String_Node_Str"+ port;
  }
 else {
    serverURI=protocol + getOrgId() + "String_Node_Str"+ MESSAGING+ "String_Node_Str"+ this.getDomain()+ "String_Node_Str"+ port;
  }
  try {
    mqttAsyncClient=new MqttAsyncClient(serverURI,clientId,DATA_STORE);
    mqttAsyncClient.setCallback(mqttCallback);
    mqttClientOptions=new MqttConnectOptions();
    if (clientUsername != null) {
      mqttClientOptions.setUserName(clientUsername);
    }
    if (clientPassword != null) {
      mqttClientOptions.setPassword(clientPassword.toCharArray());
    }
    mqttClientOptions.setCleanSession(this.isCleanSession());
    if (this.keepAliveInterval != -1) {
      mqttClientOptions.setKeepAliveInterval(this.keepAliveInterval);
    }
    mqttClientOptions.setMaxInflight(getMaxInflight());
    mqttClientOptions.setAutomaticReconnect(isAutomaticReconnect());
    SSLContext sslContext=SSLContext.getInstance("String_Node_Str");
    sslContext.init(null,null,null);
    String serverCert=null;
    String clientCert=null;
    String clientCertKey=null;
    String certPassword=null;
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        serverCert=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        throw new RuntimeException("String_Node_Str");
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
    }
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str") || trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        clientCert=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        throw new RuntimeException("String_Node_Str");
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
      throw new RuntimeException("String_Node_Str");
    }
    if (trimedValue(options.getProperty("String_Node_Str")) != null) {
      if (trimedValue(options.getProperty("String_Node_Str")).contains("String_Node_Str")) {
        clientCertKey=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
        return;
      }
    }
 else {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str");
      return;
    }
    try {
      if (trimedValue(options.getProperty("String_Node_Str")) != null) {
        certPassword=trimedValue(options.getProperty("String_Node_Str"));
      }
 else {
        certPassword="String_Node_Str";
      }
    }
 catch (    RuntimeException e) {
      LoggerUtility.log(Level.SEVERE,CLASS_NAME,METHOD,"String_Node_Str",e);
      throw e;
    }
    mqttClientOptions.setSocketFactory(getSocketFactory(serverCert,clientCert,clientCertKey,certPassword));
  }
 catch (  Exception e) {
    LoggerUtility.warn(CLASS_NAME,METHOD,"String_Node_Str" + e.getMessage());
    e.printStackTrace();
    throw new RuntimeException(e.getMessage());
  }
}