Scrivio Interview library
DebuggingFoundations7 min read · updated 12 November 2026

A Java client fails with PKIX path building failed: unable to find valid certification path to requested target when calling an internal HTTPS service. What does it mean and how do you fix it properly?

The message means the JVM could not build a chain of certificates from the server's certificate up to a certificate authority in its trust store, so it refused the connection. For internal services the usual cause is a private company CA that is not in the JDK's cacerts, or a server that does not send its intermediate certificate. The proper fix is to add the private CA's certificate to a trust store and point the client at it, through javax.net.ssl.trustStore or the client's own SSLContext, and to fix the server's chain if an intermediate is missing; never to disable validation.

Why this question is asked

This error is a rite of passage for Java developers. It shows up the first time a service calls something inside the company over HTTPS, and the internet is full of answers that make it go away by trusting every certificate. Interviewers ask about it to see whether we understand what the JVM is checking, and whether we fix the trust problem or just hide it. In this answer, we will recap how certificate chains and trust stores work, see exactly why path building fails, fix it properly with a trust store and with an SSLContext, check the server's chain, and debug the handshake with javax.net.debug.

1A Quick Recap of Certificate Chains and Trust Stores

When our client connects over TLS, the server presents a certificate that says, in effect, this public key belongs to orders.internal.acme.com, signed by some certificate authority (CA). The client cannot know the server directly, so it checks the signature. The signer is usually an intermediate CA, whose own certificate is signed by a root CA. Following the signatures from the server's certificate, called the leaf, up through intermediates to a root is called building a certification path, or chain.

The chain is only accepted if it ends at a certificate the client already trusts, called a trust anchor. In Java, the trust anchors live in a trust store, a key store file containing CA certificates. By default the JVM uses $JAVA_HOME/lib/security/cacerts, which ships with the public CAs that browsers also trust. PKIX is simply the name of the standard algorithm for building and validating these paths.

2What the Error Actually Means

The full exception usually looks like this, often wrapped by our HTTP client.

YAML
javax.net.ssl.SSLHandshakeException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
Step throughHow the JVM decides to trust a server
  1. Server sends its chainleaf, ideally plus intermediates
  2. Start from the leafwho signed it?
  3. Is the issuer in the chain or the trust store?
    YesMove up to the issuerNoPKIX path building failed
  4. Is this certificate a trust anchor?
    YesPath found, check dates and host nameNoKeep moving up the chain

4 steps in order. Play them, or step through them one at a time.

The error appears when the walk up the chain never reaches an anchor in the client's trust store.

Read it literally: the JVM tried to build a path from the server's leaf certificate to any trust anchor in its trust store, and could not. Notice that this is not a complaint about the certificate being expired or about the host name not matching; those produce different messages. It is purely a trust problem. There are two common reasons with internal services. The first is that the company runs its own private CA, which signs internal certificates and is of course not in the JDK's public cacerts. The second is that the server sends only its leaf certificate and not the intermediate, so the JVM cannot find the link between the leaf and a root it might trust. Browsers often hide the second problem, because they cache intermediates they saw elsewhere or download them, while Java by default does not.

3Fix 1: Add the Private CA to a Trust Store

The proper fix is to trust the company's CA, not the individual server. We get the CA's root certificate from the security or platform team (not from the server we are trying to verify), and import it into a trust store with keytool.

Text
# Create a trust store with the internal root CA (PKCS12 is the default type since Java 9)
keytool -importcert -alias acme-root-ca -file acme-root-ca.pem \
-keystore /etc/acme/truststore.p12 -storepass "$TRUSTSTORE_PASSWORD" -noprompt
# Point the JVM at it
java -Djavax.net.ssl.trustStore=/etc/acme/truststore.p12 \
-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" -jar orders-client.jar

But there is a catch: javax.net.ssl.trustStore replaces the default trust store; it does not add to it. After this change the JVM trusts only the internal CA, and calls to public HTTPS services start failing with the same PKIX error. So either we build the new trust store from a copy of the JDK's cacerts plus our CA, or we leave the JVM default alone and give the internal CA only to the client that needs it, which is the next fix. In container images, many teams import the CA into the image's cacerts at build time so every service gets it the same way.

4Fix 2: Configure the Client's Own SSLContext

Instead of changing trust for the whole JVM, we can build an SSLContext that trusts the internal CA and give it to one HTTP client. In Spring Boot 3.1 and later, SSL bundles do this from configuration.

Java
# application.yaml
spring:
ssl:
bundle:
pem:
internal:
truststore:
certificate: "classpath:certs/acme-root-ca.pem"
// Java: a RestClient that uses the bundle (RestClientSsl is available since Boot 3.2)
@Bean
RestClient ordersClient(RestClient.Builder builder, RestClientSsl ssl) {
return builder.baseUrl("https://orders.internal.acme.com")
.apply(ssl.fromBundle("internal"))
.build();
}

Notice that this keeps the change small and explicit: only the orders client trusts the internal CA, and the rest of the JVM keeps its defaults. Outside Spring, the same thing is a TrustManagerFactory initialised with a KeyStore that contains the CA, turned into an SSLContext and passed to HttpClient.newBuilder().sslContext(...).

5Check That the Server Sends Its Intermediates

If the root CA is already trusted and the error still appears, look at what the server actually sends. openssl shows the chain exactly as presented.

Properties
openssl s_client -connect orders.internal.acme.com:443 -showcerts </dev/null
# Certificate chain
# 0 s:CN = orders.internal.acme.com
# i:CN = Acme Issuing CA 2
# (only one certificate: the intermediate "Acme Issuing CA 2" is missing)

Here the leaf says it was issued by Acme Issuing CA 2, but that certificate was not sent, so Java cannot connect the leaf to the root. The fix belongs on the server: configure it to send the full chain, leaf followed by intermediates. We could also add the intermediate to every client's trust store, but then every client breaks the next time the CA rotates its intermediate, so fixing the server is the right answer.

6Why a Trust-All TrustManager Is Never the Fix

The most popular wrong answer installs a TrustManager whose checkServerTrusted() method does nothing, often together with a host name verifier that accepts every name. The error disappears, and so does all the protection TLS gives us. The connection is still encrypted, but to whoever answered: anyone who can intercept traffic on the network path, a compromised proxy or a misrouted DNS entry, can present any certificate and read or change every request, including credentials and tokens. Such code also tends to escape from the test environment into production, and security scanners rightly flag it as a critical finding. The proper fixes above take a few minutes and keep the protection.

7Follow-up questions

How would you debug the handshake with -Djavax.net.debug?

Run the client with -Djavax.net.debug=ssl:handshake, or =all for everything, and reproduce the call. The output shows the protocol and cipher negotiation and, importantly, the certificate chain the server presented, so we can see the subject and issuer of each certificate and spot a missing intermediate. With the trust manager details enabled it also shows which trust store file was loaded and how many anchors it contains, which quickly reveals a JVM using a different cacerts than we thought. The output is verbose and its format changes between JDK versions, so search for the certificate and trust store lines rather than reading it all.

Should we add the server's own certificate to the trust store instead of the CA?

It works until that certificate is renewed, which with short-lived internal certificates may be days. Trusting the CA means any properly issued certificate for any internal service works, and rotation needs no client change.

8Conclusion

In this answer, we saw that PKIX path building failed means the JVM could not build a chain from the server's certificate to a trust anchor in its trust store. For internal services that is usually a private CA missing from cacerts or a server that does not send its intermediate. We fixed it by importing the CA into a trust store and pointing javax.net.ssl.trustStore or a client's SSLContext, or a Spring Boot SSL bundle, at it, checked the server's chain with openssl, and saw why a trust-all TrustManager removes the protection instead of fixing the problem.

What to say in the interviewAbout 80 seconds aloud

Open with

PKIX path building failed means the JVM could not build a certification path from the server's leaf certificate up to a trust anchor in its trust store, so the TLS handshake was rejected.

Then, if they want more

It is a trust problem, not an expiry or host name problem. With internal services there are two usual causes: the certificate is issued by a private company CA that is not in the JDK's cacerts, or the server only sends its leaf certificate without the intermediate, so the chain is broken.

To fix it properly I get the internal root CA certificate from the platform team and add it to a trust store.

Either I configure the JVM with javax.net.ssl.trustStore, remembering that this replaces the default store so it must also contain the public CAs, or, which I prefer, I give it only to the client that needs it through an SSLContext, or in Spring Boot an SSL bundle applied to the RestClient.

If the CA is already trusted, I check the chain with openssl s_client -showcerts, and if an intermediate is missing, the server configuration is fixed. To see what is happening I run with -Djavax.net.debug=ssl:handshake. What I would never do is install a trust-all TrustManager, because that turns off authentication and allows a man-in-the-middle.

About this answer

Last updated
12 November 2026
Versions it names
Java 9, Spring Boot 3.1
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A Java client fails with PKIX path building failed: unable to find valid certification...": https://scrivio-interview-library.netlify.app/java/networking/ee8bdbc7d6/