Program: 91043
Project: 91043
Buggy source:
private void deleteAccount(final WalletAccount accountToDelete){
  Preconditions.checkNotNull(accountToDelete);
  final View checkBoxView=View.inflate(getActivity(),R.layout.delkey_checkbox,null);
  final CheckBox keepAddrCheckbox=(CheckBox)checkBoxView.findViewById(R.id.checkbox);
  keepAddrCheckbox.setText(getString(R.string.keep_account_address));
  keepAddrCheckbox.setChecked(false);
  final AlertDialog.Builder deleteDialog=new AlertDialog.Builder(getActivity());
  deleteDialog.setTitle(R.string.delete_account_title);
  final WalletAccount account=_mbwManager.getSelectedAccount();
  final WalletAccount linkedAccount=Utils.getLinkedAccount(account,_mbwManager.getColuManager().getAccounts().values());
  if (account instanceof ColuAccount) {
    deleteDialog.setMessage(getString(R.string.delete_account_message) + "String_Node_Str" + getString(R.string.both_rmc_will_deleted,_mbwManager.getMetadataStorage().getLabelByAccount(account.getId()),_mbwManager.getMetadataStorage().getLabelByAccount(((ColuAccount)account).getLinkedAccount().getId())));
  }
 else   if (linkedAccount != null) {
    deleteDialog.setMessage(getString(R.string.delete_account_message) + "String_Node_Str" + getString(R.string.both_rmc_will_deleted,_mbwManager.getMetadataStorage().getLabelByAccount(account.getId()),_mbwManager.getMetadataStorage().getLabelByAccount(linkedAccount.getId())));
  }
 else {
    deleteDialog.setMessage(R.string.delete_account_message);
  }
  final boolean hasPrivateData=(accountToDelete instanceof ExportableAccount && ((ExportableAccount)accountToDelete).getExportData(AesKeyCipher.defaultKeyCipher()).privateData.isPresent());
  if (accountToDelete instanceof SingleAddressAccount && hasPrivateData) {
    deleteDialog.setView(checkBoxView);
  }
  if (accountToDelete instanceof ColuAccount && accountToDelete.canSpend()) {
    Log.d(TAG,"String_Node_Str");
    deleteDialog.setView(checkBoxView);
  }
  deleteDialog.setPositiveButton(R.string.yes,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface arg0,    int arg1){
      Log.d(TAG,"String_Node_Str");
      if (hasPrivateData) {
        Long satoshis=getPotentialBalance(accountToDelete);
        AlertDialog.Builder confirmDeleteDialog=new AlertDialog.Builder(getActivity());
        confirmDeleteDialog.setTitle(R.string.confirm_delete_pk_title);
        String label=_mbwManager.getMetadataStorage().getLabelByAccount(accountToDelete.getId());
        int labelCount=1;
        if (account instanceof ColuAccount) {
          label+="String_Node_Str" + _mbwManager.getMetadataStorage().getLabelByAccount(((ColuAccount)account).getLinkedAccount().getId());
          labelCount++;
        }
 else         if (linkedAccount != null) {
          label+="String_Node_Str" + _mbwManager.getMetadataStorage().getLabelByAccount(linkedAccount.getId());
          labelCount++;
        }
        String message;
        Optional<Address> receivingAddress=accountToDelete.getReceivingAddress();
        if (accountToDelete.isActive() && satoshis != null && satoshis > 0) {
          if (label != null && label.length() != 0) {
            String address;
            if (receivingAddress.isPresent()) {
              address=receivingAddress.get().toMultiLineString();
            }
 else {
              address="String_Node_Str";
            }
            message=getString(R.string.confirm_delete_pk_with_balance_with_label,getResources().getQuantityString(R.plurals.account_label,labelCount,label),address,accountToDelete instanceof ColuAccount ? Utils.getColuFormattedValueWithUnit(getPotentialBalanceColu(accountToDelete)) : _mbwManager.getBtcValueString(satoshis));
          }
 else {
            message=getString(R.string.confirm_delete_pk_with_balance,receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str",accountToDelete instanceof ColuAccount ? Utils.getColuFormattedValueWithUnit(getPotentialBalanceColu(accountToDelete)) : _mbwManager.getBtcValueString(satoshis));
          }
        }
 else {
          if (label != null && label.length() != 0) {
            message=getString(R.string.confirm_delete_pk_without_balance_with_label,getResources().getQuantityString(R.plurals.account_label,labelCount,label),receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str");
          }
 else {
            message=getString(R.string.confirm_delete_pk_without_balance,receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str");
          }
        }
        confirmDeleteDialog.setMessage(message);
        confirmDeleteDialog.setPositiveButton(R.string.yes,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface arg0,          int arg1){
            Log.d(TAG,"String_Node_Str");
            if (keepAddrCheckbox.isChecked() && accountToDelete instanceof SingleAddressAccount) {
              try {
                WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
                if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  coluManager.forgetPrivateKey((ColuAccount)linkedColuAccount);
                }
 else {
                  ((SingleAddressAccount)accountToDelete).forgetPrivateKey(AesKeyCipher.defaultKeyCipher());
                }
                _toaster.toast(R.string.private_key_deleted,false);
              }
 catch (              KeyCipher.InvalidKeyCipher e) {
                throw new RuntimeException(e);
              }
            }
 else {
              if (accountToDelete instanceof ColuAccount) {
                try {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  if (keepAddrCheckbox.isChecked()) {
                    coluManager.forgetPrivateKey((ColuAccount)accountToDelete);
                  }
 else {
                    coluManager.deleteAccount((ColuAccount)accountToDelete);
                    _storage.deleteAccountMetadata(accountToDelete.getId());
                    _toaster.toast("String_Node_Str",false);
                    _mbwManager.setSelectedAccount(_mbwManager.getWalletManager(false).getActiveAccounts().get(0).getId());
                    _mbwManager.getEventBus().post(new ExtraAccountsChanged());
                  }
                }
 catch (                Exception e) {
                  _toaster.toast(getString(R.string.colu_error_deleting),false);
                }
              }
 else {
                WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
                if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  coluManager.deleteAccount((ColuAccount)linkedColuAccount);
                }
 else {
                  try {
                    walletManager.deleteUnrelatedAccount(accountToDelete.getId(),AesKeyCipher.defaultKeyCipher());
                  }
 catch (                  KeyCipher.InvalidKeyCipher e) {
                    throw new RuntimeException(e);
                  }
                }
                _storage.deleteAccountMetadata(accountToDelete.getId());
                _mbwManager.setSelectedAccount(_mbwManager.getWalletManager(false).getActiveAccounts().get(0).getId());
                _toaster.toast(R.string.account_deleted,false);
                _mbwManager.getEventBus().post(new ExtraAccountsChanged());
              }
            }
            finishCurrentActionMode();
            _mbwManager.getEventBus().post(new AccountChanged(accountToDelete.getId()));
          }
        }
);
        confirmDeleteDialog.setNegativeButton(R.string.no,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface arg0,          int arg1){
          }
        }
);
        confirmDeleteDialog.show();
      }
 else {
        if (accountToDelete instanceof ColuAccount) {
          ColuManager coluManager=_mbwManager.getColuManager();
          coluManager.deleteAccount((ColuAccount)accountToDelete);
        }
 else {
          WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
          if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
            ColuManager coluManager=_mbwManager.getColuManager();
            coluManager.deleteAccount((ColuAccount)linkedColuAccount);
            _storage.deleteAccountMetadata(linkedColuAccount.getId());
          }
 else {
            try {
              walletManager.deleteUnrelatedAccount(accountToDelete.getId(),AesKeyCipher.defaultKeyCipher());
            }
 catch (            KeyCipher.InvalidKeyCipher e) {
              throw new RuntimeException(e);
            }
          }
        }
        _storage.deleteAccountMetadata(accountToDelete.getId());
        finishCurrentActionMode();
        _mbwManager.getEventBus().post(new AccountChanged(accountToDelete.getId()));
        _mbwManager.getEventBus().post(new ExtraAccountsChanged());
        _toaster.toast(R.string.account_deleted,false);
      }
    }
    private CurrencyValue getPotentialBalanceColu(    WalletAccount account){
      if (account.isArchived()) {
        return null;
      }
 else {
        CurrencyBasedBalance balance=account.getCurrencyBasedBalance();
        return balance.confirmed;
      }
    }
    private Long getPotentialBalance(    WalletAccount account){
      if (account.isArchived()) {
        return null;
      }
 else {
        Balance balance=account.getBalance();
        return balance.confirmed + balance.pendingChange + balance.pendingReceiving;
      }
    }
  }
);
  deleteDialog.setNegativeButton(R.string.no,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface arg0,    int arg1){
    }
  }
);
  deleteDialog.show();
}

Fixed version (ground truth):
private void deleteAccount(final WalletAccount accountToDelete){
  Preconditions.checkNotNull(accountToDelete);
  final View checkBoxView=View.inflate(getActivity(),R.layout.delkey_checkbox,null);
  final CheckBox keepAddrCheckbox=(CheckBox)checkBoxView.findViewById(R.id.checkbox);
  keepAddrCheckbox.setText(getString(R.string.keep_account_address));
  keepAddrCheckbox.setChecked(false);
  final AlertDialog.Builder deleteDialog=new AlertDialog.Builder(getActivity());
  deleteDialog.setTitle(R.string.delete_account_title);
  final WalletAccount account=_mbwManager.getSelectedAccount();
  final WalletAccount linkedAccount=Utils.getLinkedAccount(account,_mbwManager.getColuManager().getAccounts().values());
  if (account.getType() == WalletAccount.Type.COLU) {
    deleteDialog.setMessage(getString(R.string.delete_account_message) + "String_Node_Str" + getString(R.string.both_rmc_will_deleted,_mbwManager.getMetadataStorage().getLabelByAccount(account.getId()),_mbwManager.getMetadataStorage().getLabelByAccount(((ColuAccount)account).getLinkedAccount().getId())));
  }
 else   if (linkedAccount != null) {
    deleteDialog.setMessage(getString(R.string.delete_account_message) + "String_Node_Str" + getString(R.string.both_rmc_will_deleted,_mbwManager.getMetadataStorage().getLabelByAccount(account.getId()),_mbwManager.getMetadataStorage().getLabelByAccount(linkedAccount.getId())));
  }
 else {
    WalletAccount correspondingBCHAccount=_mbwManager.getWalletManager(false).getAccount(MbwManager.getBitcoinCashAccountId(account));
    if (correspondingBCHAccount != null && correspondingBCHAccount.isVisible()) {
      deleteDialog.setMessage(getString(R.string.delete_account_message) + "String_Node_Str" + getString(R.string.both_bch_will_deleted,_mbwManager.getMetadataStorage().getLabelByAccount(account.getId()),_mbwManager.getMetadataStorage().getLabelByAccount(correspondingBCHAccount.getId())));
    }
 else {
      deleteDialog.setMessage(getString(R.string.delete_account_message));
    }
  }
  final boolean hasPrivateData=(accountToDelete instanceof ExportableAccount && ((ExportableAccount)accountToDelete).getExportData(AesKeyCipher.defaultKeyCipher()).privateData.isPresent());
  if (accountToDelete instanceof SingleAddressAccount && hasPrivateData) {
    deleteDialog.setView(checkBoxView);
  }
  if (accountToDelete instanceof ColuAccount && accountToDelete.canSpend()) {
    Log.d(TAG,"String_Node_Str");
    deleteDialog.setView(checkBoxView);
  }
  deleteDialog.setPositiveButton(R.string.yes,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface arg0,    int arg1){
      Log.d(TAG,"String_Node_Str");
      if (hasPrivateData) {
        Long satoshis=getPotentialBalance(accountToDelete);
        AlertDialog.Builder confirmDeleteDialog=new AlertDialog.Builder(getActivity());
        confirmDeleteDialog.setTitle(R.string.confirm_delete_pk_title);
        String label=_mbwManager.getMetadataStorage().getLabelByAccount(accountToDelete.getId());
        int labelCount=1;
        if (account instanceof ColuAccount) {
          label+="String_Node_Str" + _mbwManager.getMetadataStorage().getLabelByAccount(((ColuAccount)account).getLinkedAccount().getId());
          labelCount++;
        }
 else         if (linkedAccount != null) {
          label+="String_Node_Str" + _mbwManager.getMetadataStorage().getLabelByAccount(linkedAccount.getId());
          labelCount++;
        }
        String message;
        Optional<Address> receivingAddress=accountToDelete.getReceivingAddress();
        if (accountToDelete.isActive() && satoshis != null && satoshis > 0) {
          if (label != null && label.length() != 0) {
            String address;
            if (receivingAddress.isPresent()) {
              address=receivingAddress.get().toMultiLineString();
            }
 else {
              address="String_Node_Str";
            }
            message=getString(R.string.confirm_delete_pk_with_balance_with_label,getResources().getQuantityString(R.plurals.account_label,labelCount,label),address,accountToDelete instanceof ColuAccount ? Utils.getColuFormattedValueWithUnit(getPotentialBalanceColu(accountToDelete)) : _mbwManager.getBtcValueString(satoshis));
          }
 else {
            message=getString(R.string.confirm_delete_pk_with_balance,receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str",accountToDelete instanceof ColuAccount ? Utils.getColuFormattedValueWithUnit(getPotentialBalanceColu(accountToDelete)) : _mbwManager.getBtcValueString(satoshis));
          }
        }
 else {
          if (label != null && label.length() != 0) {
            message=getString(R.string.confirm_delete_pk_without_balance_with_label,getResources().getQuantityString(R.plurals.account_label,labelCount,label),receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str");
          }
 else {
            message=getString(R.string.confirm_delete_pk_without_balance,receivingAddress.isPresent() ? receivingAddress.get().toMultiLineString() : "String_Node_Str");
          }
        }
        confirmDeleteDialog.setMessage(message);
        confirmDeleteDialog.setPositiveButton(R.string.yes,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface arg0,          int arg1){
            Log.d(TAG,"String_Node_Str");
            if (keepAddrCheckbox.isChecked() && accountToDelete instanceof SingleAddressAccount) {
              try {
                WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
                if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  coluManager.forgetPrivateKey((ColuAccount)linkedColuAccount);
                }
 else {
                  ((SingleAddressAccount)accountToDelete).forgetPrivateKey(AesKeyCipher.defaultKeyCipher());
                }
                _toaster.toast(R.string.private_key_deleted,false);
              }
 catch (              KeyCipher.InvalidKeyCipher e) {
                throw new RuntimeException(e);
              }
            }
 else {
              if (accountToDelete instanceof ColuAccount) {
                try {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  if (keepAddrCheckbox.isChecked()) {
                    coluManager.forgetPrivateKey((ColuAccount)accountToDelete);
                  }
 else {
                    coluManager.deleteAccount((ColuAccount)accountToDelete);
                    _storage.deleteAccountMetadata(accountToDelete.getId());
                    _toaster.toast("String_Node_Str",false);
                    _mbwManager.setSelectedAccount(_mbwManager.getWalletManager(false).getActiveAccounts().get(0).getId());
                    _mbwManager.getEventBus().post(new ExtraAccountsChanged());
                  }
                }
 catch (                Exception e) {
                  _toaster.toast(getString(R.string.colu_error_deleting),false);
                }
              }
 else {
                WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
                if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
                  ColuManager coluManager=_mbwManager.getColuManager();
                  coluManager.deleteAccount((ColuAccount)linkedColuAccount);
                }
 else {
                  try {
                    walletManager.deleteUnrelatedAccount(accountToDelete.getId(),AesKeyCipher.defaultKeyCipher());
                  }
 catch (                  KeyCipher.InvalidKeyCipher e) {
                    throw new RuntimeException(e);
                  }
                }
                _storage.deleteAccountMetadata(accountToDelete.getId());
                _mbwManager.setSelectedAccount(_mbwManager.getWalletManager(false).getActiveAccounts().get(0).getId());
                _toaster.toast(R.string.account_deleted,false);
                _mbwManager.getEventBus().post(new ExtraAccountsChanged());
              }
            }
            finishCurrentActionMode();
            _mbwManager.getEventBus().post(new AccountChanged(accountToDelete.getId()));
          }
        }
);
        confirmDeleteDialog.setNegativeButton(R.string.no,new DialogInterface.OnClickListener(){
          public void onClick(          DialogInterface arg0,          int arg1){
          }
        }
);
        confirmDeleteDialog.show();
      }
 else {
        if (accountToDelete instanceof ColuAccount) {
          ColuManager coluManager=_mbwManager.getColuManager();
          coluManager.deleteAccount((ColuAccount)accountToDelete);
        }
 else {
          WalletAccount linkedColuAccount=Utils.getLinkedAccount(accountToDelete,_mbwManager.getColuManager().getAccounts().values());
          if (linkedColuAccount != null && linkedColuAccount instanceof ColuAccount) {
            ColuManager coluManager=_mbwManager.getColuManager();
            coluManager.deleteAccount((ColuAccount)linkedColuAccount);
            _storage.deleteAccountMetadata(linkedColuAccount.getId());
          }
 else {
            try {
              walletManager.deleteUnrelatedAccount(accountToDelete.getId(),AesKeyCipher.defaultKeyCipher());
            }
 catch (            KeyCipher.InvalidKeyCipher e) {
              throw new RuntimeException(e);
            }
          }
        }
        _storage.deleteAccountMetadata(accountToDelete.getId());
        finishCurrentActionMode();
        _mbwManager.getEventBus().post(new AccountChanged(accountToDelete.getId()));
        _mbwManager.getEventBus().post(new ExtraAccountsChanged());
        _toaster.toast(R.string.account_deleted,false);
      }
    }
    private CurrencyValue getPotentialBalanceColu(    WalletAccount account){
      if (account.isArchived()) {
        return null;
      }
 else {
        CurrencyBasedBalance balance=account.getCurrencyBasedBalance();
        return balance.confirmed;
      }
    }
    private Long getPotentialBalance(    WalletAccount account){
      if (account.isArchived()) {
        return null;
      }
 else {
        Balance balance=account.getBalance();
        return balance.confirmed + balance.pendingChange + balance.pendingReceiving;
      }
    }
  }
);
  deleteDialog.setNegativeButton(R.string.no,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface arg0,    int arg1){
    }
  }
);
  deleteDialog.show();
}