Program: 8356
Project: 8356
Buggy source:
@Override public Dialog onCreateDialog(Bundle savedInstanceState){
  final FragmentActivity context=getActivity();
  final LayoutInflater mInflater;
  mWillBeMasterKey=getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY);
  mInflater=context.getLayoutInflater();
  CustomAlertDialogBuilder dialog=new CustomAlertDialogBuilder(context);
  View view=mInflater.inflate(R.layout.add_subkey_dialog,null);
  dialog.setView(view);
  dialog.setTitle(R.string.title_add_subkey);
  mNoExpiryCheckBox=(CheckBox)view.findViewById(R.id.add_subkey_no_expiry);
  mExpiryRow=(TableRow)view.findViewById(R.id.add_subkey_expiry_row);
  mExpiryDatePicker=(DatePicker)view.findViewById(R.id.add_subkey_expiry_date_picker);
  mAlgorithmSpinner=(Spinner)view.findViewById(R.id.add_subkey_algorithm);
  mKeySizeSpinner=(Spinner)view.findViewById(R.id.add_subkey_size);
  mCustomKeyTextView=(TextView)view.findViewById(R.id.add_subkey_custom_key_size_label);
  mCustomKeyEditText=(EditText)view.findViewById(R.id.add_subkey_custom_key_size_input);
  mCustomKeyInfoTextView=(TextView)view.findViewById(R.id.add_subkey_custom_key_size_info);
  mFlagCertify=(CheckBox)view.findViewById(R.id.add_subkey_flag_certify);
  mFlagSign=(CheckBox)view.findViewById(R.id.add_subkey_flag_sign);
  mFlagEncrypt=(CheckBox)view.findViewById(R.id.add_subkey_flag_encrypt);
  mFlagAuthenticate=(CheckBox)view.findViewById(R.id.add_subkey_flag_authenticate);
  mNoExpiryCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
    @Override public void onCheckedChanged(    CompoundButton buttonView,    boolean isChecked){
      if (isChecked) {
        mExpiryRow.setVisibility(View.GONE);
      }
 else {
        mExpiryRow.setVisibility(View.VISIBLE);
      }
    }
  }
);
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    mExpiryDatePicker.setMinDate(new Date().getTime() + DateUtils.DAY_IN_MILLIS);
  }
  ArrayList<Choice> choices=new ArrayList<Choice>();
  choices.add(new Choice(PublicKeyAlgorithmTags.DSA,getResources().getString(R.string.dsa)));
  if (!mWillBeMasterKey) {
    choices.add(new Choice(PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT,getResources().getString(R.string.elgamal)));
  }
  choices.add(new Choice(PublicKeyAlgorithmTags.RSA_GENERAL,getResources().getString(R.string.rsa)));
  ArrayAdapter<Choice> adapter=new ArrayAdapter<Choice>(context,android.R.layout.simple_spinner_item,choices);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  mAlgorithmSpinner.setAdapter(adapter);
  for (int i=0; i < choices.size(); ++i) {
    if (choices.get(i).getId() == PublicKeyAlgorithmTags.RSA_GENERAL) {
      mAlgorithmSpinner.setSelection(i);
      break;
    }
  }
  ArrayAdapter<CharSequence> keySizeAdapter=new ArrayAdapter<CharSequence>(context,android.R.layout.simple_spinner_item,new ArrayList<CharSequence>(Arrays.asList(getResources().getStringArray(R.array.rsa_key_size_spinner_values))));
  keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  mKeySizeSpinner.setAdapter(keySizeAdapter);
  mKeySizeSpinner.setSelection(1);
  dialog.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface di,    int id){
      di.dismiss();
      Choice newKeyAlgorithmChoice=(Choice)mAlgorithmSpinner.getSelectedItem();
      int newKeySize=getProperKeyLength(newKeyAlgorithmChoice.getId(),getSelectedKeyLength());
      int flags=0;
      if (mFlagCertify.isChecked()) {
        flags|=KeyFlags.CERTIFY_OTHER;
      }
      if (mFlagSign.isChecked()) {
        flags|=KeyFlags.SIGN_DATA;
      }
      if (mFlagEncrypt.isChecked()) {
        flags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
      }
      if (mFlagAuthenticate.isChecked()) {
        flags|=KeyFlags.AUTHENTICATION;
      }
      long expiry;
      if (mNoExpiryCheckBox.isChecked()) {
        expiry=0L;
      }
 else {
        Calendar selectedCal=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
        selectedCal.set(mExpiryDatePicker.getYear(),mExpiryDatePicker.getMonth(),mExpiryDatePicker.getDayOfMonth());
        expiry=selectedCal.getTime().getTime() / 1000;
      }
      SaveKeyringParcel.SubkeyAdd newSubkey=new SaveKeyringParcel.SubkeyAdd(newKeyAlgorithmChoice.getId(),newKeySize,flags,expiry);
      mAlgorithmSelectedListener.onAlgorithmSelected(newSubkey);
    }
  }
);
  dialog.setCancelable(true);
  dialog.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface di,    int id){
      di.dismiss();
    }
  }
);
  final AlertDialog alertDialog=dialog.show();
  mCustomKeyEditText.addTextChangedListener(new TextWatcher(){
    @Override public void beforeTextChanged(    CharSequence s,    int start,    int count,    int after){
    }
    @Override public void onTextChanged(    CharSequence s,    int start,    int before,    int count){
    }
    @Override public void afterTextChanged(    Editable s){
      setOkButtonAvailability(alertDialog);
    }
  }
);
  mKeySizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      setCustomKeyVisibility();
      setOkButtonAvailability(alertDialog);
    }
    @Override public void onNothingSelected(    AdapterView<?> parent){
    }
  }
);
  mAlgorithmSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      updateUiForAlgorithm(((Choice)parent.getSelectedItem()).getId());
      setCustomKeyVisibility();
      setOkButtonAvailability(alertDialog);
    }
    @Override public void onNothingSelected(    AdapterView<?> parent){
    }
  }
);
  return alertDialog;
}

Fixed version (ground truth):
@Override public Dialog onCreateDialog(Bundle savedInstanceState){
  final FragmentActivity context=getActivity();
  final LayoutInflater mInflater;
  mWillBeMasterKey=getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY);
  mInflater=context.getLayoutInflater();
  CustomAlertDialogBuilder dialog=new CustomAlertDialogBuilder(context);
  View view=mInflater.inflate(R.layout.add_subkey_dialog,null);
  dialog.setView(view);
  dialog.setTitle(R.string.title_add_subkey);
  mNoExpiryCheckBox=(CheckBox)view.findViewById(R.id.add_subkey_no_expiry);
  mExpiryRow=(TableRow)view.findViewById(R.id.add_subkey_expiry_row);
  mExpiryDatePicker=(DatePicker)view.findViewById(R.id.add_subkey_expiry_date_picker);
  mAlgorithmSpinner=(Spinner)view.findViewById(R.id.add_subkey_algorithm);
  mKeySizeSpinner=(Spinner)view.findViewById(R.id.add_subkey_size);
  mCustomKeyTextView=(TextView)view.findViewById(R.id.add_subkey_custom_key_size_label);
  mCustomKeyEditText=(EditText)view.findViewById(R.id.add_subkey_custom_key_size_input);
  mCustomKeyInfoTextView=(TextView)view.findViewById(R.id.add_subkey_custom_key_size_info);
  mFlagCertify=(CheckBox)view.findViewById(R.id.add_subkey_flag_certify);
  mFlagSign=(CheckBox)view.findViewById(R.id.add_subkey_flag_sign);
  mFlagEncrypt=(CheckBox)view.findViewById(R.id.add_subkey_flag_encrypt);
  mFlagAuthenticate=(CheckBox)view.findViewById(R.id.add_subkey_flag_authenticate);
  mNoExpiryCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
    @Override public void onCheckedChanged(    CompoundButton buttonView,    boolean isChecked){
      if (isChecked) {
        mExpiryRow.setVisibility(View.GONE);
      }
 else {
        mExpiryRow.setVisibility(View.VISIBLE);
      }
    }
  }
);
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    mExpiryDatePicker.setMinDate(new Date().getTime() + DateUtils.DAY_IN_MILLIS);
  }
  ArrayList<Choice> choices=new ArrayList<Choice>();
  choices.add(new Choice(PublicKeyAlgorithmTags.DSA,getResources().getString(R.string.dsa)));
  if (!mWillBeMasterKey) {
    choices.add(new Choice(PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT,getResources().getString(R.string.elgamal)));
  }
  choices.add(new Choice(PublicKeyAlgorithmTags.RSA_GENERAL,getResources().getString(R.string.rsa)));
  ArrayAdapter<Choice> adapter=new ArrayAdapter<Choice>(context,android.R.layout.simple_spinner_item,choices);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  mAlgorithmSpinner.setAdapter(adapter);
  for (int i=0; i < choices.size(); ++i) {
    if (choices.get(i).getId() == PublicKeyAlgorithmTags.RSA_GENERAL) {
      mAlgorithmSpinner.setSelection(i);
      break;
    }
  }
  ArrayAdapter<CharSequence> keySizeAdapter=new ArrayAdapter<CharSequence>(context,android.R.layout.simple_spinner_item,new ArrayList<CharSequence>(Arrays.asList(getResources().getStringArray(R.array.rsa_key_size_spinner_values))));
  keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  mKeySizeSpinner.setAdapter(keySizeAdapter);
  mKeySizeSpinner.setSelection(1);
  dialog.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface di,    int id){
      di.dismiss();
      Choice newKeyAlgorithmChoice=(Choice)mAlgorithmSpinner.getSelectedItem();
      int newKeySize=getProperKeyLength(newKeyAlgorithmChoice.getId(),getSelectedKeyLength());
      int flags=0;
      if (mFlagCertify.isChecked()) {
        flags|=KeyFlags.CERTIFY_OTHER;
      }
      if (mFlagSign.isChecked()) {
        flags|=KeyFlags.SIGN_DATA;
      }
      if (mFlagEncrypt.isChecked()) {
        flags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
      }
      if (mFlagAuthenticate.isChecked()) {
        flags|=KeyFlags.AUTHENTICATION;
      }
      long expiry;
      if (mNoExpiryCheckBox.isChecked()) {
        expiry=0L;
      }
 else {
        Calendar selectedCal=Calendar.getInstance(TimeZone.getDefault());
        selectedCal.set(mExpiryDatePicker.getYear(),mExpiryDatePicker.getMonth(),mExpiryDatePicker.getDayOfMonth());
        selectedCal.setTimeZone(TimeZone.getTimeZone("String_Node_Str"));
        expiry=selectedCal.getTime().getTime() / 1000;
      }
      SaveKeyringParcel.SubkeyAdd newSubkey=new SaveKeyringParcel.SubkeyAdd(newKeyAlgorithmChoice.getId(),newKeySize,flags,expiry);
      mAlgorithmSelectedListener.onAlgorithmSelected(newSubkey);
    }
  }
);
  dialog.setCancelable(true);
  dialog.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface di,    int id){
      di.dismiss();
    }
  }
);
  final AlertDialog alertDialog=dialog.show();
  mCustomKeyEditText.addTextChangedListener(new TextWatcher(){
    @Override public void beforeTextChanged(    CharSequence s,    int start,    int count,    int after){
    }
    @Override public void onTextChanged(    CharSequence s,    int start,    int before,    int count){
    }
    @Override public void afterTextChanged(    Editable s){
      setOkButtonAvailability(alertDialog);
    }
  }
);
  mKeySizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      setCustomKeyVisibility();
      setOkButtonAvailability(alertDialog);
    }
    @Override public void onNothingSelected(    AdapterView<?> parent){
    }
  }
);
  mAlgorithmSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView<?> parent,    View view,    int position,    long id){
      updateUiForAlgorithm(((Choice)parent.getSelectedItem()).getId());
      setCustomKeyVisibility();
      setOkButtonAvailability(alertDialog);
    }
    @Override public void onNothingSelected(    AdapterView<?> parent){
    }
  }
);
  return alertDialog;
}