ex.printStackTrace(); return null;
throw new CertPathValidatorException(ex);
    final TrustAnchor findTrustAnchor(        X509Certificate cert,        Set             trustAnchors)         throws CertPathValidatorException    {        Iterator iter = trustAnchors.iterator();        TrustAnchor trust = null;        PublicKey trustPublicKey = null;        Exception invalidKeyEx = null;        X509CertSelector certSelectX509 = new X509CertSelector();        try        {            certSelectX509.setSubject(getIssuerPrincipal(cert).getEncoded());        }        catch (IOException ex)        {            ex.printStackTrace();            return null;        }        while (iter.hasNext() && trust == null)        {            trust = (TrustAnchor)iter.next();            if (trust.getTrustedCert() != null)            {                if (certSelectX509.match(trust.getTrustedCert()))                {                    trustPublicKey = trust.getTrustedCert().getPublicKey();                }                else                {                    trust = null;                }            }            else if (trust.getCAName() != null                        && trust.getCAPublicKey() != null)            {                try                {                    X500Principal certIssuer = getIssuerPrincipal(cert);                    X500Principal caName = new X500Principal(trust.getCAName());                    if (certIssuer.equals(caName))                    {                        trustPublicKey = trust.getCAPublicKey();                    }                    else                    {                        trust = null;                    }                }                catch (IllegalArgumentException ex)                {                    trust = null;                }            }            else            {                trust = null;            }                        if (trustPublicKey != null)            {                try                {                    cert.verify(trustPublicKey);                }                catch (Exception ex)                {                    invalidKeyEx = ex;                    trust = null;                }            }        }            if (trust == null && invalidKeyEx != null)        {            throw new CertPathValidatorException("TrustAnchor found put certificate validation failed",invalidKeyEx);        }        return trust;    }