{"record":{"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":"critical","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java","lineNumber":626,"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":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L608-L644","documentation":"A KafkaException thrown by KafkaAdminClient.createInternal wrapping any Throwable raised while building the Metrics, NetworkClient, and the KafkaAdminClient instance. It is a fatal 'the client never came up' error: the partially-built Metrics and NetworkClient are closed before re-throwing.","triggerScenarios":"Any failure during the production createInternal path: invalid config that passed type checks but failed at runtime, Metrics construction failure, NetworkClient construction failure, ClientTelemetryReporter setup error, or an OutOfMemoryError. The original cause is chained as the exception's cause.","commonSituations":"Misconfigured security (SASL/SSL) that throws during channel setup; a MetricsReporter plugin that throws in its constructor; missing or incompatible client-telemetry setup; classpath issues where a required class is absent.","solutions":["Inspect exception.getCause() to find the real failure (often a ConfigException, IOException, or NoClassDefFoundError).","Fix the underlying cause: correct security config, remove/fix the broken MetricsReporter, resolve classpath.","If the cause is transient (DNS, temp network), retry Admin.create once it is resolved."],"exampleFix":"// before\nAdmin admin = Admin.create(props); // throws KafkaException\n\n// after\ntry {\n    admin = Admin.create(props);\n} catch (KafkaException e) {\n    log.error(\"Admin create failed: {}\", e.getCause());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    this.admin = Admin.create(props);\n} catch (KafkaException e) {\n    Throwable cause = e.getCause();\n    log.error(\"Admin creation failed; cause: {}\", cause == null ? \"unknown\" : cause.toString());\n    throw e;\n}","preventionTips":["Always inspect getCause() — the real failure is nested.","Validate security (SASL/SSL) and reporter configs before constructing the client.","Fail fast in startup probes so a bad Admin config does not pass health checks."],"tags":["kafka-admin","client-setup","lifecycle","wrapped-exception"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}