Program: 85613
Project: 85613
Buggy source:
/** 
 * Uses the provided PKI method to find the corresponding public key and verify the provided signature.
 * @param paymentRequest Payment request to verify.
 * @param trustStore KeyStore of trusted root certificate authorities.
 * @return verification data, or null if no PKI method was specified in the {@link Protos.PaymentRequest}.
 * @throws PaymentProtocolException if payment request could not be verified.
 */
public static @Nullable PkiVerificationData verifyPaymentRequestPki(Protos.PaymentRequest paymentRequest,KeyStore trustStore) throws PaymentProtocolException {
  List<X509Certificate> certs=null;
  try {
    final String pkiType=paymentRequest.getPkiType();
    if (pkiType.equals("String_Node_Str"))     return null;
    String algorithm;
    if (pkiType.equals("String_Node_Str"))     algorithm="String_Node_Str";
 else     if (pkiType.equals("String_Node_Str"))     algorithm="String_Node_Str";
 else     throw new PaymentProtocolException.InvalidPkiType("String_Node_Str" + pkiType);
    Protos.X509Certificates protoCerts=Protos.X509Certificates.parseFrom(paymentRequest.getPkiData());
    if (protoCerts.getCertificateCount() == 0)     throw new PaymentProtocolException.InvalidPkiData("String_Node_Str");
    CertificateFactory certificateFactory=CertificateFactory.getInstance("String_Node_Str");
    certs=Lists.newArrayList();
    for (    ByteString bytes : protoCerts.getCertificateList())     certs.add((X509Certificate)certificateFactory.generateCertificate(bytes.newInput()));
    CertPath path=certificateFactory.generateCertPath(certs);
    PKIXParameters params=new PKIXParameters(trustStore);
    params.setRevocationEnabled(false);
    CertPathValidator validator=CertPathValidator.getInstance("String_Node_Str");
    PKIXCertPathValidatorResult result=(PKIXCertPathValidatorResult)validator.validate(path,params);
    PublicKey publicKey=result.getPublicKey();
    Signature signature=Signature.getInstance(algorithm);
    signature.initVerify(publicKey);
    Protos.PaymentRequest.Builder reqToCheck=paymentRequest.toBuilder();
    reqToCheck.setSignature(ByteString.EMPTY);
    signature.update(reqToCheck.build().toByteArray());
    if (!signature.verify(paymentRequest.getSignature().toByteArray()))     throw new PaymentProtocolException.PkiVerificationException("String_Node_Str");
    final X509Certificate cert=certs.get(0);
    String displayName=X509Utils.getDisplayNameFromCertificate(cert,true);
    if (displayName == null)     throw new PaymentProtocolException.PkiVerificationException("String_Node_Str");
    return new PkiVerificationData(displayName,publicKey,result.getTrustAnchor());
  }
 catch (  InvalidProtocolBufferException e) {
    throw new PaymentProtocolException.InvalidPkiData(e);
  }
catch (  CertificateException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
catch (  InvalidAlgorithmParameterException e) {
    throw new RuntimeException(e);
  }
catch (  CertPathValidatorException e) {
    throw new PaymentProtocolException.PkiVerificationException(e,certs);
  }
catch (  InvalidKeyException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  SignatureException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  KeyStoreException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
/** 
 * Uses the provided PKI method to find the corresponding public key and verify the provided signature.
 * @param paymentRequest Payment request to verify.
 * @param trustStore KeyStore of trusted root certificate authorities.
 * @return verification data, or null if no PKI method was specified in the {@link Protos.PaymentRequest}.
 * @throws PaymentProtocolException if payment request could not be verified.
 */
@Nullable public static PkiVerificationData verifyPaymentRequestPki(Protos.PaymentRequest paymentRequest,KeyStore trustStore) throws PaymentProtocolException {
  List<X509Certificate> certs=null;
  try {
    final String pkiType=paymentRequest.getPkiType();
    if (pkiType.equals("String_Node_Str"))     return null;
    String algorithm;
    if (pkiType.equals("String_Node_Str"))     algorithm="String_Node_Str";
 else     if (pkiType.equals("String_Node_Str"))     algorithm="String_Node_Str";
 else     throw new PaymentProtocolException.InvalidPkiType("String_Node_Str" + pkiType);
    Protos.X509Certificates protoCerts=Protos.X509Certificates.parseFrom(paymentRequest.getPkiData());
    if (protoCerts.getCertificateCount() == 0)     throw new PaymentProtocolException.InvalidPkiData("String_Node_Str");
    CertificateFactory certificateFactory=CertificateFactory.getInstance("String_Node_Str");
    certs=Lists.newArrayList();
    for (    ByteString bytes : protoCerts.getCertificateList())     certs.add((X509Certificate)certificateFactory.generateCertificate(bytes.newInput()));
    CertPath path=certificateFactory.generateCertPath(certs);
    PKIXParameters params=new PKIXParameters(trustStore);
    params.setRevocationEnabled(false);
    CertPathValidator validator=CertPathValidator.getInstance("String_Node_Str");
    PKIXCertPathValidatorResult result=(PKIXCertPathValidatorResult)validator.validate(path,params);
    PublicKey publicKey=result.getPublicKey();
    Signature signature=Signature.getInstance(algorithm);
    signature.initVerify(publicKey);
    Protos.PaymentRequest.Builder reqToCheck=paymentRequest.toBuilder();
    reqToCheck.setSignature(ByteString.EMPTY);
    signature.update(reqToCheck.build().toByteArray());
    if (!signature.verify(paymentRequest.getSignature().toByteArray()))     throw new PaymentProtocolException.PkiVerificationException("String_Node_Str");
    final X509Certificate cert=certs.get(0);
    String displayName=X509Utils.getDisplayNameFromCertificate(cert,true);
    if (displayName == null)     throw new PaymentProtocolException.PkiVerificationException("String_Node_Str");
    return new PkiVerificationData(displayName,publicKey,result.getTrustAnchor());
  }
 catch (  InvalidProtocolBufferException e) {
    throw new PaymentProtocolException.InvalidPkiData(e);
  }
catch (  CertificateException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
catch (  InvalidAlgorithmParameterException e) {
    throw new RuntimeException(e);
  }
catch (  CertPathValidatorException e) {
    throw new PaymentProtocolException.PkiVerificationException(e,certs);
  }
catch (  InvalidKeyException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  SignatureException e) {
    throw new PaymentProtocolException.PkiVerificationException(e);
  }
catch (  KeyStoreException e) {
    throw new RuntimeException(e);
  }
}