Troubleshooting
What the trustAnchors parameter must be non-empty MQTT error means
Short answer
The trustAnchors parameter must be non-empty exception is the Java TLS engine reporting that the trust store your MQTT client opened holds no certificates, so it cannot validate the broker. Fix it on the client host: import the broker's public server certificate and its CA into that client-side trust store, restart the client, and reconnect. A certificate installed only on the broker never populates the client's store.

On this page
- What does the trustAnchors parameter must be non-empty error mean?
- Why does one MQTT client connect over TLS while another fails?
- Which trust store does the failing client actually read?
- How do I import the broker certificate into the client trust store?
- Do I need a client certificate for one-way TLS?
- Does installing the certificate on the broker fix the client?
- What else makes a Java trust store read as empty?
- How do I verify the connection after the import?
- Questions asked
The fix lives on the client host, not the broker: import the broker's public server certificate and its CA certificate into the Java trust store the failing MQTT client actually reads, restart the client, and reconnect. The exception java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty is the Java TLS engine reporting that the store it opened holds no trust anchors at all, so the broker's certificate cannot be validated before any MQTT traffic flows. This walkthrough covers where that store lives for a Java MQTT client bundled with a server installation, the keytool commands that populate it, why one-way TLS needs no client certificate, and why a certificate installed on the broker alone never fixes the client.
What does the trustAnchors parameter must be non-empty error mean? #
It means the trust store the client's JVM opened holds zero certificates, so certificate validation has no anchor to build on: PKIX validation needs at least one trust anchor — a CA the client trusts before any connection is made — and an empty set makes the TLS layer throw before the MQTT CONNECT is attempted.
The full trace names the chain: java.lang.RuntimeException: Unexpected error, wrapping java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty. Initialization of the trust manager fails against a store that yields no anchors, so the client never gets as far as examining the broker's certificate. That is also why a client offering only a TLS on/off switch can fail with TLS enabled: the switch turns TLS on, but the trust material sits in a store file the JVM reads, and nothing in the connect dialog populates that file.
Why does one MQTT client connect over TLS while another fails? #
Because trust material is per client, not per network: a desktop test client with certificate fields in its connect dialog takes the broker certificate and CA files you hand it directly, while a Java client without such fields reads a trust store file on its host — different stores, different results.
Trust is not shared across the wire. The working test client proves exactly one thing: the broker's listener and certificate chain are sound. It says nothing about the Java client's store, which can be empty on the same network at the same minute — which is why the same broker serves one client happily and rejects the other.
Which trust store does the failing client actually read? #
The one on the client's own host: for a Java MQTT client bundled with a server installation, it is a JKS file shipped beside that installation — one documented deployment names it security/clientcerts.jks — never a trust store sitting on the broker host.
Two layouts cover most installs. A bundled client opens its host application's own client trust store; a standalone client with no store configured falls back to the JVM default, which an application can override with the javax.net.ssl.trustStore system property. The rule that decides every case: the store is opened on the client's host, when its TLS context initializes. When client and broker share one edge PC — a layout covered in When one edge PC can host the MQTT broker for the rest — the client still reads its own store, not the broker's files.
How do I import the broker certificate into the client trust store? #
With the JDK's keytool: import the broker's public server certificate and its CA certificate as two entries in the client-side store, then restart the client so a fresh TLS context reads the updated file. No private key is involved and nothing changes on the broker.
Worked example, with example names to replace with your own: the broker exports its server certificate as mqtt-broker.crt and the signing CA as mqtt-root-ca.crt, and the client's store is the JKS in the installation's security folder, currently holding 0 entries. Run keytool twice from the installation folder; without a -storepass argument it prompts for the store password interactively:
keytool -importcert -alias mqtt-broker -file mqtt-broker.crt -keystore security/clientcerts.jks
keytool -importcert -alias mqtt-root-ca -file mqtt-root-ca.crt -keystore security/clientcerts.jks
The arithmetic is 0 entries + 1 server certificate + 1 CA certificate = 2 entries, and the listing must show exactly that:
keytool -list -keystore security/clientcerts.jks
If the broker handed you PEM files and the import rejects one, convert it once with openssl x509 -in mqtt-root-ca.pem -outform der -out mqtt-root-ca.crt and import the DER file. The import changes nothing on the broker; if the listener itself still needs preparing for remote TLS clients, the page on configuring Mosquitto 2.0 listeners for remote Node-RED walks through the broker-side certificate lines.
Do I need a client certificate for one-way TLS? #
No. One-way TLS validates only the broker: the client needs the broker's public certificate and CA in its trust store, and the broker never asks the client to identify itself with a certificate. Client certificates belong to mutual TLS, a separate configuration on both ends.
The confusion is understandable, because vendor instructions aimed at client authentication populate stores on both sides and have the broker request a client identity. That is a different feature. For one-way TLS the client-side import is the whole requirement, and the client presents nothing about itself; one-way TLS lets a client connect with no client certificate at all, as set out in Why an MQTT client connects without its TLS client certificate. Some products wrap the identical store operations in their own screens: the documentation for one industrial MQTT agent states that its agents manage broker server certificates through the Java KeyStore and provide import, list, and delete operations.
Does installing the certificate on the broker fix the client? #
No. The trusting side holds the trust material: a certificate installed only on broker B does nothing for a client on host A, which opens its own store when the TLS context initializes. A accepts B when B's CA is in A's store or B's certificate is imported there.
The client never opens the broker's store, so two dead ends follow from forgetting that. Two brokers signed by the same CA do not fix an unpopulated client store: the shared CA helps only once it sits in the client's store on each client host. And a client on host A does accept broker B with no import at all when B chains to a CA the client already holds, including the public CAs in a JVM default store. Each client host needs its own import; nothing on B populates A.
What else makes a Java trust store read as empty? #
Three causes beyond a truly empty file: a wrong store password that keeps the JVM from opening the store, a type mismatch such as PKCS12 declared for a JKS file, and a client that has not been restarted since the import. All three throw the same exception.
Check each before touching the broker:
- Store path. A relative path in the client's configuration resolves against the client's working directory, not yours; confirm the exact file you imported into is the file the client was pointed at.
- Store password. A wrong password makes keytool complain at import or list time, and makes the JVM fail to open the store at connect time; the trust-anchors exception follows either way. Published troubleshooting reports behind this message on a PKCS12 truststore list the same trio: empty store, incorrect password, unusable store file.
- Store type. Declare the type the file actually is; a JVM told to read a PKCS12 truststore as JKS cannot open it.
- Restart. The running client built its TLS context at startup; importing into the file without restarting leaves the old, empty context in memory.
How do I verify the connection after the import? #
Restart the client and reconnect: no exception means the handshake validated the broker; the same trustAnchors message means the JVM opened a different store than the one you wrote; a certificate-path error means the store is populated but missing the CA that signed the broker.
Work the outcomes in order and stop at the first that matches:
- The session connects. The broker log now shows the client on the TLS listener; the fix stands and nothing further is needed.
- The same exception returns. The JVM opened a store other than the one you wrote: recheck the client's configured store path and the
javax.net.ssl.trustStoreproperty, and run keytool -list against the exact file to confirm your 2 entries. - A certificate-path failure appears instead, worded by the JDK as "unable to find valid certification path to requested target". The store is populated but holds no CA matching the broker's chain: import the CA that signed the current broker certificate. For the related failure where a CA file is lost to a power event on the edge box, the walkthrough MQTT connect fails after power loss when the CA certificate is missing covers the recovery.
- keytool itself reports a password or integrity error. Correct the store password before running the client; the client hits the same wall otherwise.
Every case except the first is decided on the client host: this error is never fixed by re-signing or reinstalling the broker.
Questions asked
Does the trustAnchors error mean the broker is refusing my connection?
No. The exception is thrown on the client host while the TLS trust manager is initialized, before any broker certificate is fetched or checked, so the broker's log usually shows no failed attempt at all. Treat it as a client-side configuration fault: the store the client opened holds no CA, and nothing on the broker side can cause or cure it.
Where does the Java runtime keep its default CA certificates?
In a file called cacerts inside the runtime's security folder: under lib/security in current JDK releases and under jre/lib/security in Java 8 layouts. A trimmed or embedded runtime image can ship with an empty or missing cacerts file, and then every TLS connection from that JVM fails with the same trust-anchors message, not only MQTT.
Can I make the error go away by trusting every certificate?
No. A trust manager that accepts any certificate removes broker authentication, so credentials, process values, and commands can be intercepted or spoofed by anything sitting between the client and the broker on the plant network. The supported fix is importing the CA that actually signed the broker certificate into the client trust store and leaving validation enabled.
The broker certificate was renewed and a working client now fails again — why?
A renewed certificate is accepted only if it chains to a CA the client trusts. A new issuing CA, or a chain through an intermediate the store does not hold, breaks validation that worked the day before. Import the new CA alongside the old entry, keep both during the rollout, and retire the old one once every client host has migrated.


