if (certs.size() == 1)
if (certs.size() < 2)
    private List sortCerts(        List certs)    {        if (certs.size() == 1)        {            return certs;        }                try        {            X509Principal   issuer = PrincipalUtil.getIssuerX509Principal(((X509Certificate)certs.get(0)));            boolean         okay = true;                        for (int i = 1; i != certs.size(); i++)             {                X509Certificate cert = (X509Certificate)certs.get(i);                                if (issuer.equals(PrincipalUtil.getSubjectX509Principal(cert)))                {                    issuer = PrincipalUtil.getIssuerX509Principal(((X509Certificate)certs.get(i)));                }                else                {                    okay = false;                    break;                }            }                        if (okay)            {                return certs;            }                        // find end-entity cert            ArrayList       retList = new ArrayList(certs.size());                        for (int i = 0; i < certs.size(); i++)            {                X509Certificate cert = (X509Certificate)certs.get(i);                boolean         found = false;                                X509Principal   subject = PrincipalUtil.getSubjectX509Principal(cert);                                for (int j = 0; j != certs.size(); j++)                {                    X509Certificate c = (X509Certificate)certs.get(j);                    if (PrincipalUtil.getIssuerX509Principal(c).equals(subject))                    {                        found = true;                        break;                    }                }                                if (!found)                {                    retList.add(cert);                    certs.remove(i);                }            }                        // can only have one end entity cert - something's wrong, give up.            if (retList.size() > 1)            {                for (int i = 0; i != certs.size(); i++)                {                    retList.add(certs.get(i));                }                                return retList;            }                        for (int i = 0; i != retList.size(); i++)            {                issuer = PrincipalUtil.getIssuerX509Principal((X509Certificate)retList.get(i));                                for (int j = 0; j < certs.size(); j++)                {                    X509Certificate c = (X509Certificate)certs.get(j);                    if (issuer.equals(PrincipalUtil.getSubjectX509Principal(c)))                    {                        retList.add(c);                        certs.remove(j);                        break;                    }                }            }                        // make sure all certificates are accounted for.            for (int i = 0; i != certs.size(); i++)            {                retList.add(certs.get(i));            }                        return retList;        }        catch (Exception e)        {            return certs;        }    }