code: public void validatePath() throws CertificateVerificationException {
  
          Security.addProvider(new BouncyCastleProvider());
          CollectionCertStoreParameters params = new CollectionCertStoreParameters(fullCertChain);
          try {
              CertStore store = CertStore.getInstance("Collection", params, Constants.BOUNCY_CASTLE_PROVIDER);
  
              // create certificate path
              CertificateFactory fact = CertificateFactory
                      .getInstance(Constants.X_509, Constants.BOUNCY_CASTLE_PROVIDER);
  
              CertPath certPath = fact.generateCertPath(certChain);
              TrustAnchor trustAnchor = new TrustAnchor(fullCertChain.get(fullCertChain.size() - 1), null);
              Set<TrustAnchor> trust = Collections.singleton(trustAnchor);
  
              // perform validation
              CertPathValidator validator = CertPathValidator
                      .getInstance(Constants.ALGORITHM, Constants.BOUNCY_CASTLE_PROVIDER);
              PKIXParameters param = new PKIXParameters(trust);
  
              param.addCertPathChecker(pathChecker);
              param.setRevocationEnabled(false);
              param.addCertStore(store);
              param.setDate(new Date());
  
              validator.validate(certPath, param);
              if (LOG.isInfoEnabled()) {
                  LOG.info("Certificate path validated");
              }
          } catch (CertPathValidatorException e) {
              throw new CertificateVerificationException(
                      "Certificate path validation failed on certificate number " + e.getIndex() + ", details: " + e
                              .getMessage(), e);
          } catch (Exception e) {
              throw new CertificateVerificationException("Certificate path validation failed", e);
          }
      }
docs: Certificate Path Validation process
  
  @throws CertificateVerificationException if validation process fails.