Program: 52397
Project: 52397
Buggy source:
protected CertPathBuilderResult build(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;
  PKIXCertPathValidatorSpi validator;
  CertPathBuilderResult builderResult=null;
  try {
    cFact=new CertificateFactory();
    validator=new PKIXCertPathValidatorSpi();
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str");
  }
  try {
    if (CertPathValidatorUtilities.findTrustAnchor(tbvCert,pkixParams.getBaseParameters().getTrustAnchors(),pkixParams.getBaseParameters().getSigProvider()) != null) {
      CertPath certPath=null;
      PKIXCertPathValidatorResult result=null;
      try {
        certPath=cFact.engineGenerateCertPath(tbvPath);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      try {
        result=(PKIXCertPathValidatorResult)validator.engineValidate(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();
        builderResult=build(issuer,pkixParams,tbvPath);
      }
    }
  }
 catch (  AnnotatedException e) {
    certPathException=e;
  }
  if (builderResult == null) {
    tbvPath.remove(tbvCert);
  }
  return builderResult;
}

Fixed version (ground truth):
protected CertPathBuilderResult build(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;
  PKIXCertPathValidatorSpi validator;
  CertPathBuilderResult builderResult=null;
  try {
    cFact=new CertificateFactory();
    validator=new PKIXCertPathValidatorSpi();
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str");
  }
  try {
    if (CertPathValidatorUtilities.isIssuerTrustAnchor(tbvCert,pkixParams.getBaseParameters().getTrustAnchors(),pkixParams.getBaseParameters().getSigProvider())) {
      CertPath certPath=null;
      PKIXCertPathValidatorResult result=null;
      try {
        certPath=cFact.engineGenerateCertPath(tbvPath);
      }
 catch (      Exception e) {
        throw new AnnotatedException("String_Node_Str",e);
      }
      try {
        result=(PKIXCertPathValidatorResult)validator.engineValidate(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();
        builderResult=build(issuer,pkixParams,tbvPath);
      }
    }
  }
 catch (  AnnotatedException e) {
    certPathException=e;
  }
  if (builderResult == null) {
    tbvPath.remove(tbvCert);
  }
  return builderResult;
}