code: public static X509Certificate[] exportRootCertificates(final KeyStore ks, final String alias) throws KeyStoreException {
          logKeyStore(ks);
          
          final List<X509Certificate> trustedCerts = new ArrayList<X509Certificate>();
          
          if (Strings.isNullOrEmpty(alias)) {
              
              if(log.isDebugEnabled()) {
                  log.debug("No alias given, will trust all of the certificates in the store");
              }
              
              final List<String> aliases = toList(ks.aliases());
              
              for (final String _alias : aliases) {
  
                  if (ks.isCertificateEntry(_alias)) {
                      final X509Certificate cert = (X509Certificate) ks.getCertificate(_alias);
                      if (cert != null) {
                          trustedCerts.add(cert);
                      } else {
                          log.error("Alias {} does not exist", _alias);
                      }
                  }
              }
          } else {
              if (ks.isCertificateEntry(alias)) {
                  final X509Certificate cert = (X509Certificate) ks.getCertificate(alias);
                  if (cert != null) {
                      trustedCerts.add(cert);
                  } else {
                      log.error("Alias {} does not exist", alias);
                  }
              } else {
                  log.error("Alias {} does not contain a certificate entry", alias);
              }
          }
  
          return trustedCerts.toArray(new X509Certificate[0]);
      }
docs: TODO check