question: private CertPath buildCertPath ( X509Certificate endCert ) throws CertificatePathBuildingException { CertPathBuilder cpb = null ; try { cpb = CertPathBuilder . getInstance ( "PKIX" ) ; } catch ( NoSuchAlgorithmException e ) { throw new CertificatePathBuildingException ( "Error building CertPathBuilder:" + e . getMessage ( ) , e ) ; } PKIXBuilderParameters params = CreatePKIXBuilderParameters ( endCert ) ; CertPathBuilderResult cpbResult ; try { cpbResult = cpb . build ( params ) ; } catch ( CertPathBuilderException e ) { throw new CertificatePathBuildingException ( e . getMessage ( ) , e . getCause ( ) ) ; } catch ( InvalidAlgorithmParameterException e ) { throw new CertificatePathBuildingException ( e . getMessage ( ) , e ) ; } CertPath cp = cpbResult . getCertPath ( ) ; return cp ; }
target:  build and validate cert path from end certificate. Note: the certpath return seems only include intermediate CA unless there is none in which case the end cert is returned.