Program: 94055
Project: 94055
Buggy source:
private void onConnectionStateChange_synchronized(BluetoothGatt gatt,int status,int newState){
  if (newState == BluetoothProfile.STATE_DISCONNECTED) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    if (!m_queue.fail(P_Task_Connect.class,m_device)) {
      if (!m_queue.succeed(P_Task_Disconnect.class,m_device)) {
        m_device.onNativeDisconnect(false);
      }
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTING) {
    if (Utils.isSuccess(status)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_device.onConnecting(false,false);
      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_CONNECTING);
        m_queue.add(task);
      }
      m_queue.fail(P_Task_Disconnect.class,m_device);
    }
 else {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
      m_queue.fail(P_Task_Connect.class,m_device);
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTED) {
    if (Utils.isSuccess(status)) {
      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();
      }
    }
 else {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
      if (!m_queue.fail(P_Task_Connect.class,m_device)) {
        m_device.onConnectFail((PE_TaskState)null);
      }
      if (status == PS_GattStatus.UNKNOWN_STATUS_FOR_IMMEDIATE_CONNECTION_FAILURE) {
      }
    }
  }
 else   if (newState == BluetoothProfile.STATE_DISCONNECTING) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
    m_device.onDisconnecting();
    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_CONNECTING);
      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(BluetoothGatt gatt,int status,int newState){
  if (newState == BluetoothProfile.STATE_DISCONNECTED) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
    if (!m_queue.fail(P_Task_Connect.class,m_device)) {
      if (!m_queue.succeed(P_Task_Disconnect.class,m_device)) {
        m_device.onNativeDisconnect(false);
      }
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTING) {
    if (Utils.isSuccess(status)) {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt,newState);
      m_device.onConnecting(false,false);
      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 {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
      m_queue.fail(P_Task_Connect.class,m_device);
    }
  }
 else   if (newState == BluetoothProfile.STATE_CONNECTED) {
    if (Utils.isSuccess(status)) {
      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();
      }
    }
 else {
      m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
      if (!m_queue.fail(P_Task_Connect.class,m_device)) {
        m_device.onConnectFail((PE_TaskState)null);
      }
      if (status == PS_GattStatus.UNKNOWN_STATUS_FOR_IMMEDIATE_CONNECTION_FAILURE) {
      }
    }
  }
 else   if (newState == BluetoothProfile.STATE_DISCONNECTING) {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
    m_device.onDisconnecting();
    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);
      m_queue.add(task);
    }
    m_queue.fail(P_Task_Connect.class,m_device);
  }
 else {
    m_device.m_nativeWrapper.updateNativeConnectionState(gatt);
  }
}