Blog Java · PKI
Java TLS PKI JKS

How to Fix PKIX path building failed in Java

The complete guide to sun.security.validator.ValidatorException: PKIX path building failed — what it means, why it happens, and the exact steps to fix it.

By Navsatech Team · March 2026 · 8 min read

What does the error actually mean?

When Java throws this error, it means the SSL/TLS library tried to build a trust path from the server's certificate up to a trusted root CA — and failed. Java couldn't verify that the certificate is trusted.

Full stack trace
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:
  PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
  unable to find valid certification path to requested target

The key phrase is "unable to find valid certification path". Java's certificate validator follows a chain: your server certificate was signed by an intermediate CA, which was signed by a root CA. If any link in that chain is missing from Java's trust store, the whole chain fails — even if the certificate itself is perfectly valid.

Why does it happen?

There are four root causes, in order of frequency:

01
Missing intermediate certificate
The most common cause. The server is presenting only its leaf certificate but not the intermediate CA that signed it. Java can't complete the chain.

This is extremely common with internal CAs (company-issued certs), SWIFT, and any certificate that wasn't issued by a major public CA like Let's Encrypt or DigiCert.
02
Root CA not in Java's trust store
The root CA that signed the certificate is not in the JVM's default trust store (cacerts). Common with internal/private CAs, self-signed root certificates, and older enterprise CA infrastructure.
03
Self-signed certificate
The certificate is self-signed and hasn't been added to the trust store. Java does not trust self-signed certificates by default.
04
Wrong certificate order in the bundle
Certificates are present but in the wrong order in the PEM bundle or keystore. Java expects: leaf → intermediate → root.

Fix it — JKS Keystore

If your application uses a JKS keystore (.jks file), the fix is to import the missing intermediate and root certificates into the trust store.

Step 1 — Identify what's missing

First, inspect your keystore to see what certificates are currently present:

keytool -list -v -keystore your-truststore.jks -storepass changeit

Look at the Owner and Issuer fields. If the issuer of your server certificate isn't present as a trusted entry, that's your missing link.

Step 2 — Get the missing certificate

You can download it from the server directly:

openssl s_client -connect your-server.com:443 -showcerts 2>/dev/null \
  | openssl x509 -outform PEM > intermediate.pem

Or fetch the full chain and save each cert separately:

openssl s_client -connect your-server.com:443 -showcerts 2>/dev/null \
  | awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/{ print > "cert" NR ".pem" }'

Step 3 — Import into your trust store

# Import intermediate CA
keytool -importcert -alias intermediate-ca \
  -file intermediate.pem \
  -keystore your-truststore.jks \
  -storepass changeit

# Import root CA
keytool -importcert -alias root-ca \
  -file root.pem \
  -keystore your-truststore.jks \
  -storepass changeit

Step 4 — Verify the chain is complete

keytool -list -v -keystore your-truststore.jks -storepass changeit | grep "Owner\|Issuer"

Fix it — PKCS#12

If you're using a .p12 or .pfx file, you need to rebuild it to include the full chain.

# Rebuild PKCS12 with full chain included
openssl pkcs12 -export \
  -in server.crt \
  -inkey server.key \
  -certfile intermediate.pem \
  -out server-with-chain.p12 \
  -name "server-cert" \
  -passout pass:yourpassword

The -certfile flag includes the intermediate (and optionally root) CA alongside the server certificate in the bundle.

Fix it — Live TLS endpoint

If the error is coming from a live server rather than a local keystore, the server itself is not sending the intermediate certificate during the TLS handshake.

Verify what the server is actually sending:

openssl s_client -connect your-server.com:443 -showcerts 2>/dev/null

Count the certificates in the output. If you only see one (BEGIN CERTIFICATE appears once), the server is not sending the intermediate. The fix is server-side — update your web server config to include the full chain file.

Nginx
ssl_certificate /etc/ssl/fullchain.pem;
# fullchain.pem = leaf + intermediate
Apache
SSLCertificateFile /etc/ssl/server.crt
SSLCertificateChainFile /etc/ssl/intermediate.crt
Tomcat
certificateChainFile=
  "/etc/ssl/intermediate.pem"

Diagnose it in seconds with CertLens

Instead of running multiple OpenSSL commands and reading raw output, you can upload your keystore or enter your domain in CertLens and get a visual chain diagram immediately showing exactly which certificate is missing and why the chain fails.

Free certificate chain analyser
Upload your JKS, PKCS#12, or PEM file — or enter a domain. CertLens rebuilds the trust chain, identifies missing intermediates, and gives you the exact fix commands.
Analyse Your Certificate →
✓ Detects missing intermediate certs
✓ Supports JKS, PKCS#12, PEM
✓ Visual chain diagram
✓ Ready-to-run fix commands
✓ Files never stored

Preventing it in production

This error almost always appears at the worst time — during a deployment, before a go-live, or when a certificate is renewed. Here's how to prevent it:

📋
Always test with a full chain check after renewal
Run openssl verify -CAfile chain.pem cert.pem before deploying any renewed certificate.
📦
Store full chains, not just leaf certificates
Always include the intermediate CA when creating PKCS#12 bundles or configuring keystores.
📅
Monitor certificate expiry proactively
Use CertLens Monitor to scan your domains on a schedule and get alerted before certificates expire.
🔁
Automate renewal with CI/CD checks
Add a certificate chain validation step to your deployment pipeline so broken chains are caught before they reach production.
Copilot
CertLens Copilot
AI-powered PKI assistant
Hi! I'm CertLens Copilot — ask me anything about certificates, TLS errors, JKS keystores, SWIFT PKI, or trust chain issues.