{"record":{"id":"f229db3bee3632f0","repo":"eclipse-vertx/vert.x","slug":"keymanagerfactory-is-not-present-or-is-not-initial","errorCode":null,"errorMessage":"KeyManagerFactory is not present or is not initialized yet","messagePattern":"KeyManagerFactory is not present or is not initialized yet","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/net/KeyManagerFactoryOptions.java","lineNumber":60,"sourceCode":" * <pre>\n * // with a KeyManager\n * options.setKeyCertOptions(KeyCertOptions.wrap(keyManager));\n *\n * // with a KeyManagerFactory\n * options.setKeyCertOptions(KeyCertOptions.wrap(keyManagerFactory));\n * </pre>\n *\n * @author <a href=\"mailto:hakangoudberg@hotmail.com\">Hakan Altindag</a>\n */\nclass KeyManagerFactoryOptions implements KeyCertOptions {\n\n  private final KeyManagerFactory keyManagerFactory;\n\n  KeyManagerFactoryOptions(KeyManagerFactory keyManagerFactory) {\n    if (keyManagerFactory == null\n      || keyManagerFactory.getKeyManagers() == null\n      || keyManagerFactory.getKeyManagers().length == 0) {\n      throw new IllegalArgumentException(\"KeyManagerFactory is not present or is not initialized yet\");\n    }\n    this.keyManagerFactory = keyManagerFactory;\n  }\n\n  KeyManagerFactoryOptions(X509KeyManager keyManager) {\n    this(new KeyManagerFactoryWrapper(keyManager));\n  }\n\n  private KeyManagerFactoryOptions(KeyManagerFactoryOptions other) {\n    this.keyManagerFactory = other.keyManagerFactory;\n  }\n\n  @Override\n  public KeyCertOptions copy() {\n    return new KeyManagerFactoryOptions(this);\n  }\n\n  @Override","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/net/KeyManagerFactoryOptions.java#L42-L78","documentation":"The KeyManagerFactoryOptions constructor requires a KeyManagerFactory that is non-null and already initialized (its getKeyManagers() array is non-null and non-empty). Passing a freshly created but uninitialized factory or null throws IllegalArgumentException.","triggerScenarios":"Calling new KeyManagerFactoryOptions(kmf) where kmf is null, or where kmf was created via KeyManagerFactory.getInstance(...) but init(KeyStore, char[]) was never called (so getKeyManagers() returns null or empty).","commonSituations":"Building TLS client/server options with a custom KeyManagerFactory and forgetting the init() step; a factory whose KeyStore failed to load so init silently left it unusable; refactors that moved init() out of the setup path.","solutions":["Call kmf.init(keyStore, password) before wrapping it in KeyManagerFactoryOptions","Ensure the KeyStore loads successfully and contains at least one key entry","If wrapping a single X509KeyManager, use the X509KeyManager constructor overload instead"],"exampleFix":"// before\nKeyManagerFactory kmf = KeyManagerFactory.getInstance(\"SunX509\");\noptions.setKeyCertOptions(new KeyManagerFactoryOptions(kmf)); // throws\n// after\nKeyManagerFactory kmf = KeyManagerFactory.getInstance(\"SunX509\");\nkmf.init(keyStore, keyStorePassword);\noptions.setKeyCertOptions(new KeyManagerFactoryOptions(kmf));","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(kmf, \"KeyManagerFactory required\");\nkmf.init(keyStore, password); // must succeed before wrapping\nif (kmf.getKeyManagers() == null || kmf.getKeyManagers().length == 0) {\n  throw new IllegalStateException(\"KeyManagerFactory not initialized\");\n}\noptions.setKeyCertOptions(new KeyManagerFactoryOptions(kmf));","typeGuard":"boolean isInitializedKmf(KeyManagerFactory kmf) {\n  return kmf != null && kmf.getKeyManagers() != null && kmf.getKeyManagers().length > 0;\n}","tryCatchPattern":"try {\n  kmf.init(keyStore, password.toCharArray());\n  options.setKeyCertOptions(new KeyManagerFactoryOptions(kmf));\n} catch (IllegalArgumentException | KeyStoreException | NoSuchAlgorithmException e) {\n  throw new IllegalStateException(\"TLS key material setup failed\", e);\n}","preventionTips":["Always call init(KeyStore, char[]) right after KeyManagerFactory.getInstance()","Check getKeyManagers() is non-empty before passing the factory onward","Use the X509KeyManager constructor when you only have a single key manager"],"tags":["tls","ssl","keymanager","illegal-argument","initialization"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}