Program: 8425
Project: 8425
Buggy source:
public static void buildSecretKey(Context context,ArrayList<String> userIds,ArrayList<PGPSecretKey> keys,ArrayList<Integer> keysUsages,long masterKeyId,String oldPassPhrase,String newPassPhrase,ProgressDialogUpdater progress) throws ApgGeneralException, NoSuchProviderException, PGPException, NoSuchAlgorithmException, SignatureException, IOException {
  updateProgress(progress,R.string.progress_buildingKey,0,100);
  if (oldPassPhrase == null || oldPassPhrase.equals("String_Node_Str")) {
    oldPassPhrase="String_Node_Str";
  }
  if (newPassPhrase == null || newPassPhrase.equals("String_Node_Str")) {
    newPassPhrase="String_Node_Str";
  }
  updateProgress(progress,R.string.progress_preparingMasterKey,10,100);
  int usageId=keysUsages.get(0);
  boolean canSign=(usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
  boolean canEncrypt=(usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
  String mainUserId=userIds.get(0);
  PGPSecretKey masterKey=keys.get(0);
  PGPPublicKey masterPublicKey=masterKey.getPublicKey();
  masterPublicKey=PGPPublicKey.removeCertification(masterPublicKey,"String_Node_Str");
  PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray());
  PGPPrivateKey masterPrivateKey=masterKey.extractPrivateKey(keyDecryptor);
  updateProgress(progress,R.string.progress_certifyingMasterKey,20,100);
  for (  String userId : userIds) {
    PGPContentSignerBuilder signerBuilder=new JcaPGPContentSignerBuilder(masterPublicKey.getAlgorithm(),HashAlgorithmTags.SHA1).setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
    PGPSignatureGenerator sGen=new PGPSignatureGenerator(signerBuilder);
    sGen.init(PGPSignature.POSITIVE_CERTIFICATION,masterPrivateKey);
    PGPSignature certification=sGen.generateCertification(userId,masterPublicKey);
    masterPublicKey=PGPPublicKey.addCertification(masterPublicKey,userId,certification);
  }
  PGPKeyPair masterKeyPair=new PGPKeyPair(masterPublicKey,masterPrivateKey);
  PGPSignatureSubpacketGenerator hashedPacketsGen=new PGPSignatureSubpacketGenerator();
  PGPSignatureSubpacketGenerator unhashedPacketsGen=new PGPSignatureSubpacketGenerator();
  int keyFlags=KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA;
  if (canEncrypt) {
    keyFlags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
  }
  hashedPacketsGen.setKeyFlags(true,keyFlags);
  hashedPacketsGen.setPreferredSymmetricAlgorithms(true,PREFERRED_SYMMETRIC_ALGORITHMS);
  hashedPacketsGen.setPreferredHashAlgorithms(true,PREFERRED_HASH_ALGORITHMS);
  hashedPacketsGen.setPreferredCompressionAlgorithms(true,PREFERRED_COMPRESSION_ALGORITHMS);
  updateProgress(progress,R.string.progress_buildingMasterKeyRing,30,100);
  PGPDigestCalculator sha1Calc=new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
  PGPContentSignerBuilder certificationSignerBuilder=new JcaPGPContentSignerBuilder(masterKeyPair.getPublicKey().getAlgorithm(),HashAlgorithmTags.SHA1);
  PBESecretKeyEncryptor keyEncryptor=new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5,sha1Calc).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(newPassPhrase.toCharArray());
  PGPKeyRingGenerator keyGen=new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,masterKeyPair,mainUserId,sha1Calc,hashedPacketsGen.generate(),unhashedPacketsGen.generate(),certificationSignerBuilder,keyEncryptor);
  updateProgress(progress,R.string.progress_addingSubKeys,40,100);
  for (int i=1; i < keys.size(); ++i) {
    updateProgress(progress,40 + 50 * (i - 1) / (keys.size() - 1),100);
    PGPSecretKey subKey=keys.get(i);
    PGPPublicKey subPublicKey=subKey.getPublicKey();
    PBESecretKeyDecryptor keyDecryptor2=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray());
    PGPPrivateKey subPrivateKey=subKey.extractPrivateKey(keyDecryptor2);
    PGPKeyPair subKeyPair=new PGPKeyPair(subPublicKey,subPrivateKey);
    hashedPacketsGen=new PGPSignatureSubpacketGenerator();
    unhashedPacketsGen=new PGPSignatureSubpacketGenerator();
    keyFlags=0;
    usageId=keysUsages.get(i);
    canSign=(usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
    canEncrypt=(usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
    if (canSign) {
      keyFlags|=KeyFlags.SIGN_DATA;
    }
    if (canEncrypt) {
      keyFlags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
    }
    hashedPacketsGen.setKeyFlags(true,keyFlags);
    keyGen.addSubKey(subKeyPair,hashedPacketsGen.generate(),unhashedPacketsGen.generate());
  }
  PGPSecretKeyRing secretKeyRing=keyGen.generateSecretKeyRing();
  PGPPublicKeyRing publicKeyRing=keyGen.generatePublicKeyRing();
  updateProgress(progress,R.string.progress_savingKeyRing,90,100);
  ProviderHelper.saveKeyRing(context,secretKeyRing);
  ProviderHelper.saveKeyRing(context,publicKeyRing);
  updateProgress(progress,R.string.progress_done,100,100);
}

Fixed version (ground truth):
public static void buildSecretKey(Context context,ArrayList<String> userIds,ArrayList<PGPSecretKey> keys,ArrayList<Integer> keysUsages,long masterKeyId,String oldPassPhrase,String newPassPhrase,ProgressDialogUpdater progress) throws ApgGeneralException, NoSuchProviderException, PGPException, NoSuchAlgorithmException, SignatureException, IOException {
  updateProgress(progress,R.string.progress_buildingKey,0,100);
  if (oldPassPhrase == null) {
    oldPassPhrase="String_Node_Str";
  }
  if (newPassPhrase == null) {
    newPassPhrase="String_Node_Str";
  }
  updateProgress(progress,R.string.progress_preparingMasterKey,10,100);
  int usageId=keysUsages.get(0);
  boolean canSign=(usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
  boolean canEncrypt=(usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
  String mainUserId=userIds.get(0);
  PGPSecretKey masterKey=keys.get(0);
  PGPPublicKey masterPublicKey=masterKey.getPublicKey();
  PGPPublicKey masterPublicKeyRmCert=PGPPublicKey.removeCertification(masterPublicKey,"String_Node_Str");
  if (masterPublicKeyRmCert != null) {
    masterPublicKey=masterPublicKeyRmCert;
  }
  PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray());
  PGPPrivateKey masterPrivateKey=masterKey.extractPrivateKey(keyDecryptor);
  updateProgress(progress,R.string.progress_certifyingMasterKey,20,100);
  for (  String userId : userIds) {
    PGPContentSignerBuilder signerBuilder=new JcaPGPContentSignerBuilder(masterPublicKey.getAlgorithm(),HashAlgorithmTags.SHA1).setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
    PGPSignatureGenerator sGen=new PGPSignatureGenerator(signerBuilder);
    sGen.init(PGPSignature.POSITIVE_CERTIFICATION,masterPrivateKey);
    PGPSignature certification=sGen.generateCertification(userId,masterPublicKey);
    masterPublicKey=PGPPublicKey.addCertification(masterPublicKey,userId,certification);
  }
  PGPKeyPair masterKeyPair=new PGPKeyPair(masterPublicKey,masterPrivateKey);
  PGPSignatureSubpacketGenerator hashedPacketsGen=new PGPSignatureSubpacketGenerator();
  PGPSignatureSubpacketGenerator unhashedPacketsGen=new PGPSignatureSubpacketGenerator();
  int keyFlags=KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA;
  if (canEncrypt) {
    keyFlags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
  }
  hashedPacketsGen.setKeyFlags(true,keyFlags);
  hashedPacketsGen.setPreferredSymmetricAlgorithms(true,PREFERRED_SYMMETRIC_ALGORITHMS);
  hashedPacketsGen.setPreferredHashAlgorithms(true,PREFERRED_HASH_ALGORITHMS);
  hashedPacketsGen.setPreferredCompressionAlgorithms(true,PREFERRED_COMPRESSION_ALGORITHMS);
  updateProgress(progress,R.string.progress_buildingMasterKeyRing,30,100);
  PGPDigestCalculator sha1Calc=new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
  PGPContentSignerBuilder certificationSignerBuilder=new JcaPGPContentSignerBuilder(masterKeyPair.getPublicKey().getAlgorithm(),HashAlgorithmTags.SHA1);
  PBESecretKeyEncryptor keyEncryptor=new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5,sha1Calc).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(newPassPhrase.toCharArray());
  PGPKeyRingGenerator keyGen=new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,masterKeyPair,mainUserId,sha1Calc,hashedPacketsGen.generate(),unhashedPacketsGen.generate(),certificationSignerBuilder,keyEncryptor);
  updateProgress(progress,R.string.progress_addingSubKeys,40,100);
  for (int i=1; i < keys.size(); ++i) {
    updateProgress(progress,40 + 50 * (i - 1) / (keys.size() - 1),100);
    PGPSecretKey subKey=keys.get(i);
    PGPPublicKey subPublicKey=subKey.getPublicKey();
    PBESecretKeyDecryptor keyDecryptor2=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray());
    PGPPrivateKey subPrivateKey=subKey.extractPrivateKey(keyDecryptor2);
    PGPKeyPair subKeyPair=new PGPKeyPair(subPublicKey,subPrivateKey);
    hashedPacketsGen=new PGPSignatureSubpacketGenerator();
    unhashedPacketsGen=new PGPSignatureSubpacketGenerator();
    keyFlags=0;
    usageId=keysUsages.get(i);
    canSign=(usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
    canEncrypt=(usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
    if (canSign) {
      keyFlags|=KeyFlags.SIGN_DATA;
    }
    if (canEncrypt) {
      keyFlags|=KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
    }
    hashedPacketsGen.setKeyFlags(true,keyFlags);
    keyGen.addSubKey(subKeyPair,hashedPacketsGen.generate(),unhashedPacketsGen.generate());
  }
  PGPSecretKeyRing secretKeyRing=keyGen.generateSecretKeyRing();
  PGPPublicKeyRing publicKeyRing=keyGen.generatePublicKeyRing();
  updateProgress(progress,R.string.progress_savingKeyRing,90,100);
  ProviderHelper.saveKeyRing(context,secretKeyRing);
  ProviderHelper.saveKeyRing(context,publicKeyRing);
  updateProgress(progress,R.string.progress_done,100,100);
}