{"id":"0cfeac24f3477d33","repo":"apache/kafka","slug":"failed-to-create-new-kafkaadminclient","errorCode":null,"errorMessage":"Failed to create new KafkaAdminClient","messagePattern":"Failed to create new KafkaAdminClient","errorType":"exception","errorClass":"KafkaException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java","lineNumber":623,"sourceCode":"                clientId,\n                metrics,\n                \"admin-client\",\n                logContext,\n                apiVersions,\n                time,\n                1,\n                (int) TimeUnit.HOURS.toMillis(1),\n                null,\n                metadataManager.updater(),\n                (hostResolver == null) ? new DefaultHostResolver() : hostResolver,\n                null,\n                clientTelemetryReporter.map(ClientTelemetryReporter::telemetrySender).orElse(null));\n            return new KafkaAdminClient(config, clientId, time, metadataManager, metrics, networkClient,\n                timeoutProcessorFactory, logContext, clientTelemetryReporter);\n        } catch (Throwable exc) {\n            closeQuietly(metrics, \"Metrics\");\n            closeQuietly(networkClient, \"NetworkClient\");\n            throw new KafkaException(\"Failed to create new KafkaAdminClient\", exc);\n        }\n    }\n\n    // Visible for tests\n    static KafkaAdminClient createInternal(AdminClientConfig config,\n                                           AdminMetadataManager metadataManager,\n                                           KafkaClient client,\n                                           Time time) {\n        Metrics metrics = null;\n        String clientId = generateClientId(config);\n        List<MetricsReporter> reporters = CommonClientConfigs.metricsReporters(clientId, config);\n        Optional<ClientTelemetryReporter> clientTelemetryReporter = CommonClientConfigs.telemetryReporter(clientId, config);\n        clientTelemetryReporter.ifPresent(reporters::add);\n\n        try {\n            metrics = new Metrics(new MetricConfig(), reporters, time);\n            LogContext logContext = createLogContext(clientId);\n            return new KafkaAdminClient(config, clientId, time, metadataManager, metrics,","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L605-L641","documentation":"A wrapper KafkaException thrown by the catch-all in KafkaAdminClient.createInternal when any Throwable escapes while building the Metrics, NetworkClient, or AdminClientRunnable (e.g. invalid config values, SSL/TLS misconfiguration, SASL errors, DNS/resolver failures, or any earlier ConfigException). The original cause is attached as exc via the exception constructor, so resolving it requires inspecting getCause() — the outer message alone only signals that admin client construction failed.","triggerScenarios":"Any failure during Admin.create inside createInternal: a ConfigException from an invalid numeric/duration value, an IllegalArgumentException from ClientUtils.createNetworkClient, SSL/SASL/keystore errors, or a RuntimeException from Metrics/telemetry reporter setup. The catch wraps every such failure in this KafkaException and closes the partially-built Metrics and NetworkClient.","commonSituations":"Wrong type or out-of-range value for request.timeout.ms, metadata.max.age.ms, etc.; missing/unreadable SSL keystore or truststore path; SASL mechanism misconfigured; a custom MetricsReporter constructor that throws; typo'd config keys that map to a wrong type after originals() processing.","solutions":["Inspect the exception's getCause() (or the wrapped stack trace) — the actual failure and config key are described there, not in this outer message.","Fix the root cause identified by the wrapped exception (correct the config value, keystore path, SASL config, etc.).","Enable DEBUG/TRACE logging for org.apache.kafka.clients.admin and org.apache.kafka.common.network to see the failure before it is wrapped.","Validate the Admin config programmatically by constructing AdminClientConfig directly first (new AdminClientConfig(props)) so misconfigurations surface as ConfigException before the heavier NetworkClient build."],"exampleFix":"// before\ntry {\n    Admin admin = Admin.create(props);\n} catch (KafkaException e) {\n    log.error(\"Failed to create admin: {}\", e.getMessage()); // only sees the wrapper\n}\n\n// after - unwrap and log the real cause\ntry {\n    Admin admin = Admin.create(props);\n} catch (KafkaException e) {\n    Throwable cause = e.getCause() != null ? e.getCause() : e;\n    log.error(\"Failed to create admin (root cause: {})\", cause.getMessage(), cause);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Admin admin = Admin.create(props);\n} catch (KafkaException e) {\n    // Wrapper: the real cause lives in e.getCause() (ConfigException, UnknownHostException, SSL errors, ...)\n    Throwable cause = e.getCause() != null ? e.getCause() : e;\n    log.error(\"Failed to create KafkaAdminClient: {}\", cause.toString());\n}","preventionTips":["Always inspect KafkaException.getCause() — 'Failed to create new KafkaAdminClient' only wraps the real failure (DNS, TLS, SASL, bad config).","Validate all config keys and endpoint reachability (DNS resolve, port open) before calling Admin.create in a hot path.","Treat Admin creation as a fallible, side-effecting operation: build it once, cache it, and never recreate per request."],"tags":["admin-client","configuration","startup","wrapper-exception","ssl","sasl"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}