Program: 166454
Project: 166454
Buggy source:
/** 
 * Loads the keystore from the given ranger database. <p>If a password is given, it is used to check the integrity of the keystore data. Otherwise, the integrity of the keystore is not checked.
 * @param stream the input stream from which the keystore is loaded
 * @param password the (optional) password used to check the integrity ofthe keystore.
 * @exception IOException if there is an I/O or format problem with thekeystore data
 * @exception NoSuchAlgorithmException if the algorithm used to checkthe integrity of the keystore cannot be found
 * @exception CertificateException if any of the certificates in thekeystore could not be loaded
 */
public void engineLoad(InputStream stream,char[] password) throws IOException, NoSuchAlgorithmException, CertificateException {
synchronized (entries) {
    List<XXRangerKeyStore> rangerKeyDetails=dbOperationLoad();
    DataInputStream dis;
    MessageDigest md=null;
    if (rangerKeyDetails == null || rangerKeyDetails.size() < 1) {
      return;
    }
    entries.clear();
    if (password != null) {
      md=getPreKeyedHash(password);
    }
    byte computed[];
    computed=md.digest();
    for (    XXRangerKeyStore rangerKey : rangerKeyDetails) {
      String encoded=rangerKey.getEncoded();
      byte[] data=DatatypeConverter.parseBase64Binary(encoded);
      if (data != null && data.length > 0) {
        stream=new ByteArrayInputStream(data);
      }
 else {
        logger.error("String_Node_Str" + rangerKey.getAlias());
      }
      if (password != null) {
        int counter=0;
        for (int i=computed.length - 1; i >= 0; i--) {
          if (computed[i] != data[data.length - (1 + counter)]) {
            Throwable t=new UnrecoverableKeyException("String_Node_Str");
            throw (IOException)new IOException("String_Node_Str" + "String_Node_Str").initCause(t);
          }
 else {
            counter++;
          }
        }
      }
      if (password != null) {
        dis=new DataInputStream(new DigestInputStream(stream,md));
      }
 else {
        dis=new DataInputStream(stream);
      }
      ObjectInputStream ois=null;
      try {
        String alias;
        SecretKeyEntry entry=new SecretKeyEntry();
        alias=rangerKey.getAlias();
        entry.date=new Date(rangerKey.getCreatedDate());
        entry.cipher_field=rangerKey.getCipher();
        entry.bit_length=rangerKey.getBitLength();
        entry.description=rangerKey.getDescription();
        entry.version=rangerKey.getVersion();
        entry.attributes=rangerKey.getAttributes();
        try {
          ois=new ObjectInputStream(dis);
          entry.sealedKey=(SealedObject)ois.readObject();
        }
 catch (        ClassNotFoundException cnfe) {
          throw new IOException(cnfe.getMessage());
        }
        entries.put(alias,entry);
      }
  finally {
        if (ois != null) {
          ois.close();
        }
 else {
          dis.close();
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Loads the keystore from the given ranger database. <p>If a password is given, it is used to check the integrity of the keystore data. Otherwise, the integrity of the keystore is not checked.
 * @param stream the input stream from which the keystore is loaded
 * @param password the (optional) password used to check the integrity ofthe keystore.
 * @exception IOException if there is an I/O or format problem with thekeystore data
 * @exception NoSuchAlgorithmException if the algorithm used to checkthe integrity of the keystore cannot be found
 * @exception CertificateException if any of the certificates in thekeystore could not be loaded
 */
public void engineLoad(InputStream stream,char[] password) throws IOException, NoSuchAlgorithmException, CertificateException {
synchronized (entries) {
    List<XXRangerKeyStore> rangerKeyDetails=dbOperationLoad();
    DataInputStream dis;
    MessageDigest md=null;
    if (rangerKeyDetails == null || rangerKeyDetails.size() < 1) {
      return;
    }
    entries.clear();
    md=getPreKeyedHash(password);
    byte computed[];
    computed=md.digest();
    for (    XXRangerKeyStore rangerKey : rangerKeyDetails) {
      String encoded=rangerKey.getEncoded();
      byte[] data=DatatypeConverter.parseBase64Binary(encoded);
      if (data != null && data.length > 0) {
        stream=new ByteArrayInputStream(data);
      }
 else {
        logger.error("String_Node_Str" + rangerKey.getAlias());
      }
      if (password != null) {
        int counter=0;
        for (int i=computed.length - 1; i >= 0; i--) {
          if (computed[i] != data[data.length - (1 + counter)]) {
            Throwable t=new UnrecoverableKeyException("String_Node_Str");
            throw (IOException)new IOException("String_Node_Str" + "String_Node_Str").initCause(t);
          }
 else {
            counter++;
          }
        }
      }
      if (password != null) {
        dis=new DataInputStream(new DigestInputStream(stream,md));
      }
 else {
        dis=new DataInputStream(stream);
      }
      ObjectInputStream ois=null;
      try {
        String alias;
        SecretKeyEntry entry=new SecretKeyEntry();
        alias=rangerKey.getAlias();
        entry.date=new Date(rangerKey.getCreatedDate());
        entry.cipher_field=rangerKey.getCipher();
        entry.bit_length=rangerKey.getBitLength();
        entry.description=rangerKey.getDescription();
        entry.version=rangerKey.getVersion();
        entry.attributes=rangerKey.getAttributes();
        try {
          ois=new ObjectInputStream(dis);
          entry.sealedKey=(SealedObject)ois.readObject();
        }
 catch (        ClassNotFoundException cnfe) {
          throw new IOException(cnfe.getMessage());
        }
        entries.put(alias,entry);
      }
  finally {
        if (ois != null) {
          ois.close();
        }
 else {
          dis.close();
        }
      }
    }
  }
}