Program: 8364
Project: 8364
Buggy source:
/** 
 * Creates dialog
 */
@Override public Dialog onCreateDialog(Bundle savedInstanceState){
  final Activity activity=getActivity();
  final long secretKeyId=getArguments().getLong(ARG_SECRET_KEY_ID);
  mMessenger=getArguments().getParcelable(ARG_MESSENGER);
  CustomAlertDialogBuilder alert=new CustomAlertDialogBuilder(activity);
  alert.setTitle(R.string.title_authentication);
  final WrappedSecretKeyRing secretRing;
  String userId;
  if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) {
    alert.setMessage(R.string.passphrase_for_symmetric_encryption);
    secretRing=null;
  }
 else {
    try {
      ProviderHelper helper=new ProviderHelper(activity);
      secretRing=helper.getWrappedSecretKeyRing(secretKeyId);
      try {
        userId=secretRing.getPrimaryUserId();
      }
 catch (      PgpGeneralException e) {
        userId=null;
      }
    }
 catch (    ProviderHelper.NotFoundException e) {
      alert.setTitle(R.string.title_key_not_found);
      alert.setMessage(getString(R.string.key_not_found,secretKeyId));
      alert.setPositiveButton(android.R.string.ok,new OnClickListener(){
        public void onClick(        DialogInterface dialog,        int which){
          dismiss();
        }
      }
);
      alert.setCancelable(false);
      mCanKB=false;
      return alert.create();
    }
    Log.d(Constants.TAG,"String_Node_Str" + userId + "String_Node_Str");
    alert.setMessage(getString(R.string.passphrase_for,userId));
  }
  LayoutInflater inflater=activity.getLayoutInflater();
  View view=inflater.inflate(R.layout.passphrase_dialog,null);
  alert.setView(view);
  mPassphraseEditText=(EditText)view.findViewById(R.id.passphrase_passphrase);
  alert.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dismiss();
      String passphrase=mPassphraseEditText.getText().toString();
      if (secretRing == null) {
        PassphraseCacheService.addCachedPassphrase(activity,Constants.key.symmetric,passphrase,"String_Node_Str");
        Bundle data=new Bundle();
        data.putString(MESSAGE_DATA_PASSPHRASE,passphrase);
        sendMessageToHandler(MESSAGE_OKAY,data);
        return;
      }
      WrappedSecretKey unlockedSecretKey=null;
      for (      WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) {
        try {
          boolean unlocked=clickSecretKey.unlock(passphrase);
          if (unlocked) {
            unlockedSecretKey=clickSecretKey;
            break;
          }
        }
 catch (        PgpGeneralException e) {
          Toast.makeText(activity,R.string.error_could_not_extract_private_key,Toast.LENGTH_SHORT).show();
          sendMessageToHandler(MESSAGE_CANCEL);
          return;
        }
      }
      if (unlockedSecretKey == null) {
        Toast.makeText(activity,R.string.wrong_passphrase,Toast.LENGTH_SHORT).show();
        sendMessageToHandler(MESSAGE_CANCEL);
        return;
      }
      long masterKeyId=secretRing.getMasterKeyId();
      Log.d(Constants.TAG,"String_Node_Str");
      try {
        PassphraseCacheService.addCachedPassphrase(activity,masterKeyId,passphrase,secretRing.getPrimaryUserId());
      }
 catch (      PgpGeneralException e) {
        Log.e(Constants.TAG,e.getMessage());
      }
      if (unlockedSecretKey.getKeyId() != masterKeyId) {
        PassphraseCacheService.addCachedPassphrase(activity,unlockedSecretKey.getKeyId(),passphrase,unlockedSecretKey.getPrimaryUserId());
      }
      Bundle data=new Bundle();
      data.putString(MESSAGE_DATA_PASSPHRASE,passphrase);
      sendMessageToHandler(MESSAGE_OKAY,data);
    }
  }
);
  alert.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dialog.cancel();
    }
  }
);
  mCanKB=true;
  return alert.show();
}

Fixed version (ground truth):
/** 
 * Creates dialog
 */
@Override public Dialog onCreateDialog(Bundle savedInstanceState){
  final Activity activity=getActivity();
  final long secretKeyId=getArguments().getLong(ARG_SECRET_KEY_ID);
  mMessenger=getArguments().getParcelable(ARG_MESSENGER);
  CustomAlertDialogBuilder alert=new CustomAlertDialogBuilder(activity);
  alert.setTitle(R.string.title_authentication);
  final WrappedSecretKeyRing secretRing;
  String userId;
  if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) {
    alert.setMessage(R.string.passphrase_for_symmetric_encryption);
    secretRing=null;
  }
 else {
    try {
      ProviderHelper helper=new ProviderHelper(activity);
      secretRing=helper.getWrappedSecretKeyRing(secretKeyId);
      try {
        userId=secretRing.getPrimaryUserId();
      }
 catch (      PgpGeneralException e) {
        userId=null;
      }
    }
 catch (    ProviderHelper.NotFoundException e) {
      alert.setTitle(R.string.title_key_not_found);
      alert.setMessage(getString(R.string.key_not_found,secretKeyId));
      alert.setPositiveButton(android.R.string.ok,new OnClickListener(){
        public void onClick(        DialogInterface dialog,        int which){
          dismiss();
        }
      }
);
      alert.setCancelable(false);
      mCanKB=false;
      return alert.create();
    }
    Log.d(Constants.TAG,"String_Node_Str" + userId + "String_Node_Str");
    alert.setMessage(getString(R.string.passphrase_for,userId));
  }
  LayoutInflater inflater=activity.getLayoutInflater();
  View view=inflater.inflate(R.layout.passphrase_dialog,null);
  alert.setView(view);
  mPassphraseEditText=(EditText)view.findViewById(R.id.passphrase_passphrase);
  alert.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dismiss();
      String passphrase=mPassphraseEditText.getText().toString();
      if (secretRing == null) {
        PassphraseCacheService.addCachedPassphrase(activity,Constants.key.symmetric,passphrase,getString(R.string.passp_cache_notif_pwd));
        Bundle data=new Bundle();
        data.putString(MESSAGE_DATA_PASSPHRASE,passphrase);
        sendMessageToHandler(MESSAGE_OKAY,data);
        return;
      }
      WrappedSecretKey unlockedSecretKey=null;
      for (      WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) {
        try {
          boolean unlocked=clickSecretKey.unlock(passphrase);
          if (unlocked) {
            unlockedSecretKey=clickSecretKey;
            break;
          }
        }
 catch (        PgpGeneralException e) {
          Toast.makeText(activity,R.string.error_could_not_extract_private_key,Toast.LENGTH_SHORT).show();
          sendMessageToHandler(MESSAGE_CANCEL);
          return;
        }
      }
      if (unlockedSecretKey == null) {
        Toast.makeText(activity,R.string.wrong_passphrase,Toast.LENGTH_SHORT).show();
        sendMessageToHandler(MESSAGE_CANCEL);
        return;
      }
      long masterKeyId=secretRing.getMasterKeyId();
      Log.d(Constants.TAG,"String_Node_Str");
      try {
        PassphraseCacheService.addCachedPassphrase(activity,masterKeyId,passphrase,secretRing.getPrimaryUserId());
      }
 catch (      PgpGeneralException e) {
        Log.e(Constants.TAG,"String_Node_Str",e);
      }
      if (unlockedSecretKey.getKeyId() != masterKeyId) {
        PassphraseCacheService.addCachedPassphrase(activity,unlockedSecretKey.getKeyId(),passphrase,unlockedSecretKey.getPrimaryUserId());
      }
      Bundle data=new Bundle();
      data.putString(MESSAGE_DATA_PASSPHRASE,passphrase);
      sendMessageToHandler(MESSAGE_OKAY,data);
    }
  }
);
  alert.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dialog.cancel();
    }
  }
);
  mCanKB=true;
  return alert.show();
}