Program: 94016
Project: 94016
Buggy source:
private void onConnectionStateChange_synchronized(final BluetoothGatt gatt,final int gattStatus,final int newState){
  if (newState == BluetoothProfile.STATE_DISCONNECTED) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    final P_Task_Connect connectTask=m_queue.getCurrent(P_Task_Connect.class,m_device);
    if (connectTask != null) {
      connectTask.onNativeFail(gattStatus);
    }
 else {
      final P_Task_Disconnect disconnectTask=m_queue.getCurrent(P_Task_Disconnect.class,m_device);
      if (disconnectTask != null) {
        disconnectTask.onNativeSuccess(gattStatus);
      }
 else {
        m_device.onNativeDisconnect(false,gattStatus,true);
      }
    }
    m_device.m_nativeWrapper.closeGattIfNeeded(false);
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTING) {
    if (Utils.isSuccess(gattStatus)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_device.onConnecting(false,false,P_BondManager.OVERRIDE_EMPTY_STATES);
      if (!m_queue.isCurrent(P_Task_Connect.class,m_device)) {
        P_Task_Connect task=new P_Task_Connect(m_device,m_taskStateListener,false,PE_TaskPriority.FOR_IMPLICIT_BONDING_AND_CONNECTING);
        m_queue.add(task);
      }
      m_queue.fail(P_Task_Disconnect.class,m_device);
    }
 else {
      onNativeConnectFail(gatt,gattStatus);
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTED) {
    if (Utils.isSuccess(gattStatus)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_queue.fail(P_Task_Disconnect.class,m_device);
      if (!m_queue.succeed(P_Task_Connect.class,m_device)) {
        m_device.onNativeConnect(false);
      }
    }
 else {
      onNativeConnectFail(gatt,gattStatus);
    }
  }
 else   if (newState == BluetoothProfile.STATE_DISCONNECTING) {
    m_logger.e("String_Node_Str");
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    if (!m_queue.isCurrent(P_Task_Disconnect.class,m_device)) {
      P_Task_Disconnect task=new P_Task_Disconnect(m_device,m_taskStateListener,false,PE_TaskPriority.FOR_IMPLICIT_BONDING_AND_CONNECTING,true);
      m_queue.add(task);
    }
    m_queue.fail(P_Task_Connect.class,m_device);
  }
 else {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
  }
}

Fixed version (ground truth):
private void onConnectionStateChange_synchronized(final BluetoothGatt gatt,final int gattStatus,final int newState){
  if (newState == BluetoothProfile.STATE_DISCONNECTED) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    final P_Task_Connect connectTask=m_queue.getCurrent(P_Task_Connect.class,m_device);
    if (connectTask != null) {
      connectTask.onNativeFail(gattStatus);
    }
 else {
      final P_Task_Disconnect disconnectTask=m_queue.getCurrent(P_Task_Disconnect.class,m_device);
      if (disconnectTask != null) {
        disconnectTask.onNativeSuccess(gattStatus);
      }
 else {
        m_device.onNativeDisconnect(false,gattStatus,true);
      }
    }
    m_device.m_nativeWrapper.closeGattIfNeeded(false);
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTING) {
    if (Utils.isSuccess(gattStatus)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_device.onConnecting(false,false,P_BondManager.OVERRIDE_EMPTY_STATES,true);
      if (!m_queue.isCurrent(P_Task_Connect.class,m_device)) {
        P_Task_Connect task=new P_Task_Connect(m_device,m_taskStateListener,false,PE_TaskPriority.FOR_IMPLICIT_BONDING_AND_CONNECTING);
        m_queue.add(task);
      }
      m_queue.fail(P_Task_Disconnect.class,m_device);
    }
 else {
      onNativeConnectFail(gatt,gattStatus);
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTED) {
    if (Utils.isSuccess(gattStatus)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_queue.fail(P_Task_Disconnect.class,m_device);
      if (!m_queue.succeed(P_Task_Connect.class,m_device)) {
        m_device.onNativeConnect(false);
      }
    }
 else {
      onNativeConnectFail(gatt,gattStatus);
    }
  }
 else   if (newState == BluetoothProfile.STATE_DISCONNECTING) {
    m_logger.e("String_Node_Str");
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    if (!m_queue.isCurrent(P_Task_Disconnect.class,m_device)) {
      P_Task_Disconnect task=new P_Task_Disconnect(m_device,m_taskStateListener,false,PE_TaskPriority.FOR_IMPLICIT_BONDING_AND_CONNECTING,true);
      m_queue.add(task);
    }
    m_queue.fail(P_Task_Connect.class,m_device);
  }
 else {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
  }
}