Program: 52396
Project: 52396
Buggy source:
private CertPathBuilderResult build(X509AttributeCertificate attrCert,X509Certificate tbvCert,PKIXExtendedBuilderParameters pkixParams,List tbvPath){
  if (tbvPath.contains(tbvCert)) {
    return null;
  }
  if (pkixParams.getExcludedCerts().contains(tbvCert)) {
    return null;
  }
  if (pkixParams.getMaxPathLength() != -1) {
    if (tbvPath.size() - 1 > pkixParams.getMaxPathLength()) {
      return null;
    }
  }
  tbvPath.add(tbvCert);
  CertificateFactory cFact;
  CertPathValidator validator;
  CertPathBuilderResult builderResult=null;
  try {
    cFact=CertificateFactory.getInstance("String_Node_Str",BouncyCastleProvider.PROVIDER_NAME);
    validator=CertPathValidator.getInstance("String_Node_Str",BouncyCastleProvider.PROVIDER_NAME);
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str");
  }
  try {
    if (CertPathValidatorUtilities.findTrustAnchor(tbvCert,pkixParams.getBaseParameters().getTrustAnchors(),pkixParams.getBaseParameters().getSigProvider()) != null) {
      CertPath certPath;
      PKIXCertPathValidatorResult result;
      try {
        certPath=cFact.generateCertPath(tbvPath);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      try {
        result=(PKIXCertPathValidatorResult)validator.validate(certPath,pkixParams);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      return new PKIXCertPathBuilderResult(certPath,result.getTrustAnchor(),result.getPolicyTree(),result.getPublicKey());
    }
 else {
      List stores=new ArrayList();
      stores.addAll(pkixParams.getBaseParameters().getCertificateStores());
      try {
        stores.addAll(CertPathValidatorUtilities.getAdditionalStoresFromAltNames(tbvCert.getExtensionValue(Extension.issuerAlternativeName.getId()),pkixParams.getBaseParameters().getNamedCertificateStoreMap()));
      }
 catch (      CertificateParsingException e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      Collection issuers=new HashSet();
      try {
        issuers.addAll(CertPathValidatorUtilities.findIssuerCerts(tbvCert,pkixParams.getBaseParameters().getCertStores(),stores));
      }
 catch (      AnnotatedException e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      if (issuers.isEmpty()) {
        throw new AnnotatedException("String_Node_Str");
      }
      Iterator it=issuers.iterator();
      while (it.hasNext() && builderResult == null) {
        X509Certificate issuer=(X509Certificate)it.next();
        if (issuer.getIssuerX500Principal().equals(issuer.getSubjectX500Principal())) {
          continue;
        }
        builderResult=build(attrCert,issuer,pkixParams,tbvPath);
      }
    }
  }
 catch (  AnnotatedException e) {
    certPathException=new AnnotatedException("String_Node_Str",e);
  }
  if (builderResult == null) {
    tbvPath.remove(tbvCert);
  }
  return builderResult;
}

Fixed version (ground truth):
private CertPathBuilderResult build(X509AttributeCertificate attrCert,X509Certificate tbvCert,PKIXExtendedBuilderParameters pkixParams,List tbvPath){
  if (tbvPath.contains(tbvCert)) {
    return null;
  }
  if (pkixParams.getExcludedCerts().contains(tbvCert)) {
    return null;
  }
  if (pkixParams.getMaxPathLength() != -1) {
    if (tbvPath.size() - 1 > pkixParams.getMaxPathLength()) {
      return null;
    }
  }
  tbvPath.add(tbvCert);
  CertificateFactory cFact;
  CertPathValidator validator;
  CertPathBuilderResult builderResult=null;
  try {
    cFact=CertificateFactory.getInstance("String_Node_Str",BouncyCastleProvider.PROVIDER_NAME);
    validator=CertPathValidator.getInstance("String_Node_Str",BouncyCastleProvider.PROVIDER_NAME);
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str");
  }
  try {
    if (CertPathValidatorUtilities.isIssuerTrustAnchor(tbvCert,pkixParams.getBaseParameters().getTrustAnchors(),pkixParams.getBaseParameters().getSigProvider())) {
      CertPath certPath;
      PKIXCertPathValidatorResult result;
      try {
        certPath=cFact.generateCertPath(tbvPath);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      try {
        result=(PKIXCertPathValidatorResult)validator.validate(certPath,pkixParams);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      return new PKIXCertPathBuilderResult(certPath,result.getTrustAnchor(),result.getPolicyTree(),result.getPublicKey());
    }
 else {
      List stores=new ArrayList();
      stores.addAll(pkixParams.getBaseParameters().getCertificateStores());
      try {
        stores.addAll(CertPathValidatorUtilities.getAdditionalStoresFromAltNames(tbvCert.getExtensionValue(Extension.issuerAlternativeName.getId()),pkixParams.getBaseParameters().getNamedCertificateStoreMap()));
      }
 catch (      CertificateParsingException e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      Collection issuers=new HashSet();
      try {
        issuers.addAll(CertPathValidatorUtilities.findIssuerCerts(tbvCert,pkixParams.getBaseParameters().getCertStores(),stores));
      }
 catch (      AnnotatedException e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      if (issuers.isEmpty()) {
        throw new AnnotatedException("String_Node_Str");
      }
      Iterator it=issuers.iterator();
      while (it.hasNext() && builderResult == null) {
        X509Certificate issuer=(X509Certificate)it.next();
        if (issuer.getIssuerX500Principal().equals(issuer.getSubjectX500Principal())) {
          continue;
        }
        builderResult=build(attrCert,issuer,pkixParams,tbvPath);
      }
    }
  }
 catch (  AnnotatedException e) {
    certPathException=new AnnotatedException("String_Node_Str",e);
  }
  if (builderResult == null) {
    tbvPath.remove(tbvCert);
  }
  return builderResult;
}