Buggy code:
} PGPPrivateKey subPrivateKey ; if ( ! ( PgpKeyOperation . isDivertToCard ( sKey ) ) ) { PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder ( ) . setProvider ( BOUNCY_CASTLE_PROVIDER_NAME ) . build ( cryptoInput . getPassphrase ( ) . getCharArray ( ) ) ; subPrivateKey = sKey . extractPrivateKey ( keyDecryptor ) ; if ( subPrivateKey == null ) { log . add ( MSG_MF_ERROR_SUB_STRIPPED , ( indent + 1 ) , KeyFormattingUtils . convertKeyIdToHex ( change . mKeyId ) ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ; } } else { subPrivateKey = null ; } try { PGPSignature sig = PgpKeyOperation . generateSubkeyBindingSignature ( PgpKeyOperation . getSignatureGenerator ( masterSecretKey , cryptoInput ) , cryptoInput . getSignatureTime ( ) , masterPublicKey , masterPrivateKey , PgpKeyOperation . getSignatureGenerator ( sKey , cryptoInput ) , subPrivateKey , pKey , flags , expiry ) ; pKey = PGPPublicKey . addCertification ( pKey , sig ) ; sKR = PGPSecretKeyRing . insertSecretKey ( sKR , PGPSecretKey . replacePublicKey ( sKey , pKey ) ) ; } catch ( NfcInteractionNeeded e ) { nfcSignOps . addHash ( e . hashToSign , e . hashAlgo ) ; } } subProgressPop ( ) ; subProgressPush ( 60 , 65 ) ; for ( int i = 0 ; i < ( saveParcel . mRevokeSubKeys . size ( ) ) ; i ++ ) { progress ( progress_modify_subkeyrevoke , ( ( i - 1 ) * ( 100 // ( saveParcel . mRevokeSubKeys . size ( ) ) ) ) ) ; long revocation = saveParcel . mRevokeSubKeys . get ( i ) ; log . add ( MSG_MF_SUBKEY_REVOKE , indent , KeyFormattingUtils . convertKeyIdToHex ( revocation ) ) ; PGPSecretKey sKey = sKR . getSecretKey ( revocation ) ; if ( sKey == null ) { log . add ( MSG_MF_ERROR_SUBKEY_MISSING , ( indent + 1 ) , KeyFormattingUtils . convertKeyIdToHex ( revocation ) ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ; } PGPPublicKey pKey = sKey . getPublicKey ( ) ; try { PGPSignature sig = PgpKeyOperation . generateRevocationSignature ( PgpKeyOperation . getSignatureGenerator ( masterSecretKey , cryptoInput ) , cryptoInput . getSignatureTime ( ) , masterPublicKey , masterPrivateKey , pKey ) ; pKey = PGPPublicKey . addCertification ( pKey , sig ) ; sKR = PGPSecretKeyRing . insertSecretKey ( sKR , PGPSecretKey . replacePublicKey ( sKey , pKey ) ) ; } catch ( NfcInteractionNeeded e ) { nfcSignOps . addHash ( e . hashToSign , e . hashAlgo ) ; } } subProgressPop ( ) ; subProgressPush ( 70 , 90 ) ; for ( int i = 0 ; i < ( saveParcel . mAddSubKeys . size ( ) ) ; i ++ ) { if ( checkCancelled ( ) ) { log . add ( MSG_OPERATION_CANCELLED , indent ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_CANCELLED , log , null ) ; } progress ( progress_modify_subkeyadd , ( ( i - 1 ) * ( 100 // ( saveParcel . mAddSubKeys . size ( ) ) ) ) ) ; SaveKeyringParcel . SubkeyAdd add = saveParcel . mAddSubKeys . get ( i ) ; log . add ( MSG_MF_SUBKEY_NEW , indent , KeyFormattingUtils . getAlgorithmInfo ( add . mAlgorithm , add . mKeySize , add . mCurve ) ) ; if ( PgpKeyOperation . isDivertToCard ( masterSecretKey ) ) { log . add ( MSG_MF_ERROR_DIVERT_NEWSUB , ( indent + 1 ) ) ; <START_BUG> return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_CANCELLED , log , null ) ; <END_BUG> } if ( ( add . mExpiry ) == null ) { log . add ( MSG_MF_ERROR_NULL_EXPIRY , ( indent + 1 ) ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ; } if ( ( ( add . mExpiry ) > 0L ) && ( new Date ( ( ( add . mExpiry ) * 1000 ) ) . before ( new Date ( ) ) ) ) { log . add ( MSG_MF_ERROR_PAST_EXPIRY , ( indent + 1 ) ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ; } subProgressPush ( ( ( i - 1 ) * ( 100 // ( saveParcel . mAddSubKeys . size ( ) ) ) ) , ( i * ( 100 // ( saveParcel . mAddSubKeys . size ( ) ) ) ) ) ; PGPKeyPair keyPair = createKey ( add , cryptoInput . getSignatureTime ( ) , log , indent ) ; subProgressPop ( ) ; if ( keyPair == null ) { log . add ( MSG_MF_ERROR_PGP , ( indent + 1 ) ) ; return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ; } PGPPublicKey pKey = keyPair . getPublicKey ( ) ; try { PGPSignature cert = PgpKeyOperation . generateSubkeyBindingSignature ( PgpKeyOperation . getSignatureGenerator ( masterSecretKey , cryptoInput ) , cryptoInput . getSignatureTime ( ) , masterPublicKey , masterPrivateKey , PgpKeyOperation . getSignatureGenerator ( pKey , cryptoInput , false ) , keyPair . getPrivateKey ( ) , pKey , add . mFlags , add . mExpiry ) ; pKey = PGPPublicKey . addSubkeyBindingCertification ( pKey , cert ) ; } catch ( NfcInteractionNeeded e ) { nfcSignOps . addHash ( e . hashToSign , e . hashAlgo ) ; } PGPSecretKey sKey ; { PGPDigestCalculator encryptorHashCalc = new JcaPGPDigestCalculatorProviderBuilder ( ) . build ( ) . get ( SECRET_KEY_ENCRYPTOR_HASH_ALGO ) ; PBESecretKeyEncryptor keyEncryptor = new org . spongycastle . openpgp . operator . jcajce . JcePBESecretKeyEncryptorBuilder ( PgpConstants . SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO , encryptorHashCalc , PgpConstants . SECRET_KEY_ENCRYPTOR_S2K_COUNT ) . setProvider ( BOUNCY_CASTLE_PROVIDER_NAME ) . build ( cryptoInput . getPassphrase ( ) . getCharArray ( ) ) ; PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder ( ) . build ( ) . get ( SECRET_KEY_SIGNATURE_CHECKSUM_HASH_ALGO ) ;

Fix:
return new PgpEditKeyResult ( PgpEditKeyResult . RESULT_ERROR , log , null ) ;