{"record":{"id":"44bd50a789c7d9d5","repo":"openzipkin/zipkin","slug":"metrics-null-44bd50","errorCode":null,"errorMessage":"metrics == null","messagePattern":"metrics == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"zipkin-collector/kafka/src/main/java/zipkin2/collector/kafka/KafkaCollector.java","lineNumber":74,"sourceCode":"    CollectorMetrics metrics = CollectorMetrics.NOOP_METRICS;\n    String topic = \"zipkin\";\n    int streams = 1;\n\n    @Override\n    public Builder storage(StorageComponent storage) {\n      delegate.storage(storage);\n      return this;\n    }\n\n    @Override\n    public Builder sampler(CollectorSampler sampler) {\n      delegate.sampler(sampler);\n      return this;\n    }\n\n    @Override\n    public Builder metrics(CollectorMetrics metrics) {\n      if (metrics == null) throw new NullPointerException(\"metrics == null\");\n      this.metrics = metrics.forTransport(\"kafka\");\n      delegate.metrics(this.metrics);\n      return this;\n    }\n\n    /**\n     * Topic zipkin spans will be consumed from. Defaults to \"zipkin\". Multiple topics may be\n     * specified if comma delimited.\n     */\n    public Builder topic(String topic) {\n      if (topic == null) throw new NullPointerException(\"topic == null\");\n      this.topic = topic;\n      return this;\n    }\n\n    /** The bootstrapServers connect string, ex. 127.0.0.1:9092. No default. */\n    public Builder bootstrapServers(String bootstrapServers) {\n      if (bootstrapServers == null) throw new NullPointerException(\"bootstrapServers == null\");","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-collector/kafka/src/main/java/zipkin2/collector/kafka/KafkaCollector.java#L56-L92","documentation":"KafkaCollector.Builder.metrics is required: null throws NullPointerException. As with the ActiveMQ collector, the passed metrics are scoped to the 'kafka' transport via forTransport(\"kafka\") before being delegated to the core Collector builder, so per-transport counters (messages, spans, bytes, drops) work.","triggerScenarios":"Calling KafkaCollector.newBuilder(...).metrics(null) — typically DI wiring or config resolution producing null and being forwarded without a guard.","commonSituations":"Missing metrics binding in Guice/Spring; test bootstrap that skips metrics; a factory method returning null on invalid config and callers passing it through.","solutions":["Pass a real CollectorMetrics instance, minimally CollectorMetrics.NOOP_METRICS.","Fix the DI binding or config lookup that yields null.","Guard at the call site: metrics != null ? metrics : CollectorMetrics.NOOP_METRICS."],"exampleFix":"// before\nkafkaBuilder.metrics(resolveMetrics(cfg)); // returns null -> NPE\n\n// after\nCollectorMetrics m = resolveMetrics(cfg);\nkafkaBuilder.metrics(m != null ? m : CollectorMetrics.NOOP_METRICS);","handlingStrategy":"validation","validationCode":"java\nCollectorMetrics m = (metrics != null) ? metrics : CollectorMetrics.NOOP_METRICS;\nkafkaBuilder.metrics(m);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require CollectorMetrics in your collector factory signature; bind a default in DI."],"tags":["zipkin","java","kafka","collector","metrics","configuration"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}