Program: 94691
Project: 94691
Buggy source:
/** 
 * Setup a MAVLink connection using the given parameter.
 * @param connParams  Parameter used to setup the MAVLink connection.
 * @param listenerTag Used to identify the connection requester.
 * @param listener    Callback to receive the connection events.
 */
void connectMAVConnection(final ConnectionParameter connParams,final String listenerTag,final MavLinkConnectionListener listener){
  AndroidMavLinkConnection conn=mavConnections.get(connParams.getUniqueId());
  final int connectionType=connParams.getConnectionType();
  final Bundle paramsBundle=connParams.getParamsBundle();
  if (conn == null) {
switch (connectionType) {
case ConnectionType.TYPE_USB:
      final int baudRate=paramsBundle.getInt(ConnectionType.EXTRA_USB_BAUD_RATE,ConnectionType.DEFAULT_USB_BAUD_RATE);
    conn=new UsbConnection(getApplicationContext(),baudRate);
  Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_BLUETOOTH:
final String bluetoothAddress=paramsBundle.getString(ConnectionType.EXTRA_BLUETOOTH_ADDRESS);
conn=new BluetoothConnection(getApplicationContext(),bluetoothAddress);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_TCP:
final String tcpServerIp=paramsBundle.getString(ConnectionType.EXTRA_TCP_SERVER_IP);
final int tcpServerPort=paramsBundle.getInt(ConnectionType.EXTRA_TCP_SERVER_PORT,ConnectionType.DEFAULT_TCP_SERVER_PORT);
conn=new AndroidTcpConnection(getApplicationContext(),tcpServerIp,tcpServerPort);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_UDP:
final int udpServerPort=paramsBundle.getInt(ConnectionType.EXTRA_UDP_SERVER_PORT,ConnectionType.DEFAULT_UDP_SERVER_PORT);
conn=new AndroidUdpConnection(getApplicationContext(),udpServerPort);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_SOLO:
{
final String soloLinkId=paramsBundle.getString(ConnectionType.EXTRA_SOLO_LINK_ID,null);
final String linkPassword=paramsBundle.getString(ConnectionType.EXTRA_SOLO_LINK_PASSWORD,null);
conn=new SoloConnection(getApplicationContext(),soloLinkId,linkPassword);
break;
}
default :
Timber.e("String_Node_Str",connectionType);
return;
}
mavConnections.put(connParams.getUniqueId(),conn);
}
if (connectionType == ConnectionType.TYPE_UDP) {
final String pingIpAddress=paramsBundle.getString(ConnectionType.EXTRA_UDP_PING_RECEIVER_IP);
if (!TextUtils.isEmpty(pingIpAddress)) {
try {
final InetAddress resolvedAddress=InetAddress.getByName(pingIpAddress);
final int pingPort=paramsBundle.getInt(ConnectionType.EXTRA_UDP_PING_RECEIVER_PORT);
final long pingPeriod=paramsBundle.getLong(ConnectionType.EXTRA_UDP_PING_PERIOD,ConnectionType.DEFAULT_UDP_PING_PERIOD);
final byte[] pingPayload=paramsBundle.getByteArray(ConnectionType.EXTRA_UDP_PING_PAYLOAD);
((AndroidUdpConnection)conn).addPingTarget(resolvedAddress,pingPort,pingPeriod,pingPayload);
}
 catch (UnknownHostException e) {
Timber.e(e,"String_Node_Str");
}
}
}
conn.addMavLinkConnectionListener(listenerTag,listener);
if (conn.getConnectionStatus() == MavLinkConnection.MAVLINK_DISCONNECTED) {
conn.connect();
GAUtils.sendEvent(new HitBuilders.EventBuilder().setCategory(GAUtils.Category.MAVLINK_CONNECTION).setAction("String_Node_Str").setLabel(connParams.toString()));
}
}

Fixed version (ground truth):
/** 
 * Setup a MAVLink connection using the given parameter.
 * @param connParams  Parameter used to setup the MAVLink connection.
 * @param listenerTag Used to identify the connection requester.
 * @param listener    Callback to receive the connection events.
 */
void connectMAVConnection(final ConnectionParameter connParams,final String listenerTag,final MavLinkConnectionListener listener){
  AndroidMavLinkConnection conn=mavConnections.get(connParams.getUniqueId());
  final int connectionType=connParams.getConnectionType();
  final Bundle paramsBundle=connParams.getParamsBundle();
  if (conn == null) {
switch (connectionType) {
case ConnectionType.TYPE_USB:
      final int baudRate=paramsBundle.getInt(ConnectionType.EXTRA_USB_BAUD_RATE,ConnectionType.DEFAULT_USB_BAUD_RATE);
    conn=new UsbConnection(getApplicationContext(),baudRate);
  Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_BLUETOOTH:
final String bluetoothAddress=paramsBundle.getString(ConnectionType.EXTRA_BLUETOOTH_ADDRESS);
conn=new BluetoothConnection(getApplicationContext(),bluetoothAddress);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_TCP:
final String tcpServerIp=paramsBundle.getString(ConnectionType.EXTRA_TCP_SERVER_IP);
final int tcpServerPort=paramsBundle.getInt(ConnectionType.EXTRA_TCP_SERVER_PORT,ConnectionType.DEFAULT_TCP_SERVER_PORT);
conn=new AndroidTcpConnection(getApplicationContext(),tcpServerIp,tcpServerPort);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_UDP:
final int udpServerPort=paramsBundle.getInt(ConnectionType.EXTRA_UDP_SERVER_PORT,ConnectionType.DEFAULT_UDP_SERVER_PORT);
conn=new AndroidUdpConnection(getApplicationContext(),udpServerPort);
Timber.d("String_Node_Str");
break;
case ConnectionType.TYPE_SOLO:
{
Timber.i("String_Node_Str");
final String soloLinkId=paramsBundle.getString(ConnectionType.EXTRA_SOLO_LINK_ID,null);
final String linkPassword=paramsBundle.getString(ConnectionType.EXTRA_SOLO_LINK_PASSWORD,null);
conn=new SoloConnection(getApplicationContext(),soloLinkId,linkPassword);
break;
}
default :
Timber.e("String_Node_Str",connectionType);
return;
}
mavConnections.put(connParams.getUniqueId(),conn);
}
if (connectionType == ConnectionType.TYPE_UDP) {
final String pingIpAddress=paramsBundle.getString(ConnectionType.EXTRA_UDP_PING_RECEIVER_IP);
if (!TextUtils.isEmpty(pingIpAddress)) {
try {
final InetAddress resolvedAddress=InetAddress.getByName(pingIpAddress);
final int pingPort=paramsBundle.getInt(ConnectionType.EXTRA_UDP_PING_RECEIVER_PORT);
final long pingPeriod=paramsBundle.getLong(ConnectionType.EXTRA_UDP_PING_PERIOD,ConnectionType.DEFAULT_UDP_PING_PERIOD);
final byte[] pingPayload=paramsBundle.getByteArray(ConnectionType.EXTRA_UDP_PING_PAYLOAD);
((AndroidUdpConnection)conn).addPingTarget(resolvedAddress,pingPort,pingPeriod,pingPayload);
}
 catch (UnknownHostException e) {
Timber.e(e,"String_Node_Str");
}
}
}
conn.addMavLinkConnectionListener(listenerTag,listener);
if (conn.getConnectionStatus() == MavLinkConnection.MAVLINK_DISCONNECTED) {
conn.connect();
GAUtils.sendEvent(new HitBuilders.EventBuilder().setCategory(GAUtils.Category.MAVLINK_CONNECTION).setAction("String_Node_Str").setLabel(connParams.toString()));
}
}