Program: 93927
Project: 93927
Buggy source:
void disconnectWithReason(PE_TaskPriority disconnectPriority_nullable,ConnectionFailListener.Status connectionFailReasonIfConnecting,Timing timing,int gattStatus,int bondFailReason,ReadWriteListener.ReadWriteEvent txnFailReason){
  if (isNull())   return;
  final boolean cancelled=connectionFailReasonIfConnecting != null && connectionFailReasonIfConnecting.wasCancelled();
  final boolean explicit=connectionFailReasonIfConnecting != null && connectionFailReasonIfConnecting.wasExplicit();
  final BleDeviceState highestState=BleDeviceState.getTransitoryConnectionState(getStateMask());
  if (explicit) {
    m_reconnectMngr_shortTerm.stop();
  }
  if (cancelled) {
    m_useAutoConnect=m_alwaysUseAutoConnect;
    m_connectionFailMngr.onExplicitDisconnect();
  }
  final boolean wasConnecting=is_internal(CONNECTING_OVERALL);
  final boolean attemptingReconnect_longTerm=cancelled ? false : is(RECONNECTING_LONG_TERM);
  E_Intent intent=cancelled ? E_Intent.INTENTIONAL : E_Intent.UNINTENTIONAL;
  m_lastConnectOrDisconnectWasUserExplicit=intent == E_Intent.INTENTIONAL;
  final boolean cancellableFromConnect=BleDeviceConfig.bool(conf_device().disconnectIsCancellable,conf_mngr().disconnectIsCancellable);
  final boolean tryBondingWhileDisconnected=connectionFailReasonIfConnecting == Status.BONDING_FAILED && BleDeviceConfig.bool(conf_device().tryBondingWhileDisconnected,conf_mngr().tryBondingWhileDisconnected);
  final boolean underwentPossibleImplicitBondingAttempt=m_nativeWrapper.isNativelyUnbonded() && m_underwentPossibleImplicitBondingAttempt == true;
  final boolean taskIsCancellable=cancellableFromConnect == true && tryBondingWhileDisconnected == false && underwentPossibleImplicitBondingAttempt == false;
{
    saveLastDisconnect(explicit);
    final boolean saveLastDisconnectAfterTaskCompletes=connectionFailReasonIfConnecting != Status.ROGUE_DISCONNECT;
    final int taskOrdinal;
    final boolean clearQueue;
    if (isAny_internal(CONNECTED,CONNECTING_OVERALL,INITIALIZED)) {
      final P_Task_Disconnect disconnectTask=new P_Task_Disconnect(this,m_taskStateListener,true,disconnectPriority_nullable,taskIsCancellable,saveLastDisconnectAfterTaskCompletes);
      queue().add(disconnectTask);
      taskOrdinal=disconnectTask.getOrdinal();
      clearQueue=true;
    }
 else {
      taskOrdinal=-1;
      clearQueue=false;
    }
    final Object[] overrideBondingStates=m_bondMngr.getOverrideBondStatesForDisconnect(connectionFailReasonIfConnecting);
    final boolean forceMainStateTracker=explicit;
    setStateToDisconnected(attemptingReconnect_longTerm,intent,gattStatus,forceMainStateTracker,overrideBondingStates);
    m_txnMngr.cancelAllTransactions();
    if (clearQueue) {
      queue().clearQueueOf(PA_Task_RequiresConnection.class,this,taskOrdinal);
    }
    if (!attemptingReconnect_longTerm) {
      m_reconnectMngr_longTerm.stop();
    }
  }
  if (wasConnecting) {
    if (getManager().ASSERT(connectionFailReasonIfConnecting != null)) {
      m_connectionFailMngr.onConnectionFailed(connectionFailReasonIfConnecting,timing,attemptingReconnect_longTerm,gattStatus,bondFailReason,highestState,ConnectionFailListener.AutoConnectUsage.NOT_APPLICABLE,txnFailReason);
    }
  }
}

Fixed version (ground truth):
void disconnectWithReason(final PE_TaskPriority disconnectPriority_nullable,final ConnectionFailListener.Status connectionFailReasonIfConnecting,final Timing timing,final int gattStatus,final int bondFailReason,final ReadWriteListener.ReadWriteEvent txnFailReason){
  getManager().getPostManager().postToUpdateThread(new Runnable(){
    @Override public void run(){
      if (isNull())       return;
      final boolean cancelled=connectionFailReasonIfConnecting != null && connectionFailReasonIfConnecting.wasCancelled();
      final boolean explicit=connectionFailReasonIfConnecting != null && connectionFailReasonIfConnecting.wasExplicit();
      final BleDeviceState highestState=BleDeviceState.getTransitoryConnectionState(getStateMask());
      if (explicit) {
        m_reconnectMngr_shortTerm.stop();
      }
      if (cancelled) {
        m_useAutoConnect=m_alwaysUseAutoConnect;
        m_connectionFailMngr.onExplicitDisconnect();
      }
      final boolean wasConnecting=is_internal(CONNECTING_OVERALL);
      final boolean attemptingReconnect_longTerm=cancelled ? false : is(RECONNECTING_LONG_TERM);
      E_Intent intent=cancelled ? E_Intent.INTENTIONAL : E_Intent.UNINTENTIONAL;
      m_lastConnectOrDisconnectWasUserExplicit=intent == E_Intent.INTENTIONAL;
      final boolean cancellableFromConnect=BleDeviceConfig.bool(conf_device().disconnectIsCancellable,conf_mngr().disconnectIsCancellable);
      final boolean tryBondingWhileDisconnected=connectionFailReasonIfConnecting == Status.BONDING_FAILED && BleDeviceConfig.bool(conf_device().tryBondingWhileDisconnected,conf_mngr().tryBondingWhileDisconnected);
      final boolean underwentPossibleImplicitBondingAttempt=m_nativeWrapper.isNativelyUnbonded() && m_underwentPossibleImplicitBondingAttempt == true;
      final boolean taskIsCancellable=cancellableFromConnect == true && tryBondingWhileDisconnected == false && underwentPossibleImplicitBondingAttempt == false;
{
        saveLastDisconnect(explicit);
        final boolean saveLastDisconnectAfterTaskCompletes=connectionFailReasonIfConnecting != Status.ROGUE_DISCONNECT;
        final int taskOrdinal;
        final boolean clearQueue;
        if (isAny_internal(CONNECTED,CONNECTING_OVERALL,INITIALIZED)) {
          final P_Task_Disconnect disconnectTask=new P_Task_Disconnect(BleDevice.this,m_taskStateListener,true,disconnectPriority_nullable,taskIsCancellable,saveLastDisconnectAfterTaskCompletes);
          queue().add(disconnectTask);
          taskOrdinal=disconnectTask.getOrdinal();
          clearQueue=true;
        }
 else {
          taskOrdinal=-1;
          clearQueue=false;
        }
        final Object[] overrideBondingStates=m_bondMngr.getOverrideBondStatesForDisconnect(connectionFailReasonIfConnecting);
        final boolean forceMainStateTracker=explicit;
        setStateToDisconnected(attemptingReconnect_longTerm,intent,gattStatus,forceMainStateTracker,overrideBondingStates);
        m_txnMngr.cancelAllTransactions();
        if (clearQueue) {
          queue().clearQueueOf(PA_Task_RequiresConnection.class,BleDevice.this,taskOrdinal);
        }
        if (!attemptingReconnect_longTerm) {
          m_reconnectMngr_longTerm.stop();
        }
      }
      if (wasConnecting) {
        if (getManager().ASSERT(connectionFailReasonIfConnecting != null)) {
          m_connectionFailMngr.onConnectionFailed(connectionFailReasonIfConnecting,timing,attemptingReconnect_longTerm,gattStatus,bondFailReason,highestState,ConnectionFailListener.AutoConnectUsage.NOT_APPLICABLE,txnFailReason);
        }
      }
    }
  }
);
}