Program: 37865
Project: 37865
Buggy source:
public static CertificatePair generateCertificate(String DN,SerialNum serial,int days,int keySize,KeyType type,PublicKey key,CertificatePair issuer) throws Exception {
  if ((KeyType.INTERMEDIATE == type || KeyType.CLIENT == type || KeyType.SERVER == type) && issuer == null)   throw new IllegalArgumentException("String_Node_Str");
  if (issuer == null && key != null)   throw new IllegalArgumentException("String_Node_Str");
  KeyPair pair=null;
  if (key == null) {
    pair=generateRSAKeyPair(keySize);
    key=pair.getPublic();
  }
  Calendar now=Calendar.getInstance();
  Calendar expiry=Calendar.getInstance();
  expiry.add(Calendar.DAY_OF_YEAR,days);
  X500Name subjectDN=new X500Name(DN);
  X500Name issuerDN=issuer == null ? subjectDN : new X500Name(issuer.getCertificate().getSubjectX500Principal().getName());
  JcaX509v3CertificateBuilder builder=new JcaX509v3CertificateBuilder(issuerDN,serial.toBigInt(),now.getTime(),expiry.getTime(),subjectDN,key);
  JcaX509ExtensionUtils utils=new JcaX509ExtensionUtils();
  builder.addExtension(Extension.subjectKeyIdentifier,false,utils.createSubjectKeyIdentifier(key));
  if (issuer == null) {
    builder.addExtension(Extension.authorityKeyIdentifier,false,utils.createAuthorityKeyIdentifier(key));
  }
 else {
    builder.addExtension(Extension.authorityKeyIdentifier,false,utils.createAuthorityKeyIdentifier(issuer.getCertificate()));
  }
  if (KeyType.CA == type || KeyType.INTERMEDIATE == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(true));
    builder.addExtension(Extension.keyUsage,true,new KeyUsage(KeyUsage.keyEncipherment | KeyUsage.cRLSign | KeyUsage.dataEncipherment| KeyUsage.digitalSignature| KeyUsage.keyCertSign));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.anyExtendedKeyUsage));
  }
 else   if (KeyType.SERVER == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(false));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));
  }
 else   if (KeyType.CLIENT == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(false));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.id_kp_clientAuth));
  }
  ContentSigner signer=new JcaContentSignerBuilder("String_Node_Str").build(issuer == null ? pair.getPrivate() : issuer.getKey());
  X509CertificateHolder theCertHolder=builder.build(signer);
  X509Certificate theCert=new JcaX509CertificateConverter().getCertificate(theCertHolder);
  theCert.verify(issuer == null ? key : issuer.getCertificate().getPublicKey());
  return new CertificatePair(theCert,pair == null ? null : pair.getPrivate());
}

Fixed version (ground truth):
public static CertificatePair generateCertificate(String DN,SerialNum serial,int days,int keySize,KeyType type,PublicKey key,CertificatePair issuer) throws Exception {
  if ((KeyType.INTERMEDIATE == type || KeyType.CLIENT == type || KeyType.SERVER == type) && issuer == null)   throw new IllegalArgumentException("String_Node_Str");
  if (issuer == null && key != null)   throw new IllegalArgumentException("String_Node_Str");
  KeyPair pair=null;
  if (key == null) {
    pair=generateRSAKeyPair(keySize);
    key=pair.getPublic();
  }
  Calendar now=Calendar.getInstance();
  Calendar expiry=Calendar.getInstance();
  expiry.add(Calendar.DAY_OF_YEAR,days);
  X500Principal subjectDN=new X500Principal(DN);
  X500Principal issuerDN=issuer == null ? subjectDN : issuer.getCertificate().getSubjectX500Principal();
  JcaX509v3CertificateBuilder builder=new JcaX509v3CertificateBuilder(issuerDN,serial.toBigInt(),now.getTime(),expiry.getTime(),subjectDN,key);
  JcaX509ExtensionUtils utils=new JcaX509ExtensionUtils();
  builder.addExtension(Extension.subjectKeyIdentifier,false,utils.createSubjectKeyIdentifier(key));
  if (issuer == null) {
    builder.addExtension(Extension.authorityKeyIdentifier,false,utils.createAuthorityKeyIdentifier(key));
  }
 else {
    builder.addExtension(Extension.authorityKeyIdentifier,false,utils.createAuthorityKeyIdentifier(issuer.getCertificate()));
  }
  if (KeyType.CA == type || KeyType.INTERMEDIATE == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(true));
    builder.addExtension(Extension.keyUsage,true,new KeyUsage(KeyUsage.keyEncipherment | KeyUsage.cRLSign | KeyUsage.dataEncipherment| KeyUsage.digitalSignature| KeyUsage.keyCertSign));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.anyExtendedKeyUsage));
  }
 else   if (KeyType.SERVER == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(false));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));
  }
 else   if (KeyType.CLIENT == type) {
    builder.addExtension(Extension.basicConstraints,true,new BasicConstraints(false));
    builder.addExtension(Extension.extendedKeyUsage,true,new ExtendedKeyUsage(KeyPurposeId.id_kp_clientAuth));
  }
  ContentSigner signer=new JcaContentSignerBuilder("String_Node_Str").build(issuer == null ? pair.getPrivate() : issuer.getKey());
  X509CertificateHolder theCertHolder=builder.build(signer);
  X509Certificate theCert=new JcaX509CertificateConverter().getCertificate(theCertHolder);
  theCert.verify(issuer == null ? key : issuer.getCertificate().getPublicKey());
  return new CertificatePair(theCert,pair == null ? null : pair.getPrivate());
}