{"record":{"id":"8f7c05f515703645","repo":"openzipkin/zipkin","slug":"metrics-null-8f7c05","errorCode":null,"errorMessage":"metrics == null","messagePattern":"metrics == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"zipkin-collector/core/src/main/java/zipkin2/collector/Collector.java","lineNumber":66,"sourceCode":"    final Logger logger;\n    StorageComponent storage;\n    CollectorSampler sampler;\n    CollectorMetrics metrics;\n\n    Builder(Logger logger) {\n      this.logger = logger;\n    }\n\n    /** Sets {@link {@link CollectorComponent.Builder#storage(StorageComponent)}} */\n    public Builder storage(StorageComponent storage) {\n      if (storage == null) throw new NullPointerException(\"storage == null\");\n      this.storage = storage;\n      return this;\n    }\n\n    /** Sets {@link {@link CollectorComponent.Builder#metrics(CollectorMetrics)}} */\n    public Builder metrics(CollectorMetrics metrics) {\n      if (metrics == null) throw new NullPointerException(\"metrics == null\");\n      this.metrics = metrics;\n      return this;\n    }\n\n    /** Sets {@link {@link CollectorComponent.Builder#sampler(CollectorSampler)}} */\n    public Builder sampler(CollectorSampler sampler) {\n      if (sampler == null) throw new NullPointerException(\"sampler == null\");\n      this.sampler = sampler;\n      return this;\n    }\n\n    public Collector build() {\n      return new Collector(this);\n    }\n  }\n\n  final Logger logger;\n  final CollectorMetrics metrics;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-collector/core/src/main/java/zipkin2/collector/Collector.java#L48-L84","documentation":"Collector.Builder.metrics throws NullPointerException on null. Metrics count messages, spans, bytes, and drops per transport; although the Collector constructor would silently default to CollectorMetrics.NOOP_METRICS if unset, explicitly passing null is treated as a bug and rejected at the setter.","triggerScenarios":"Calling .metrics(null) — e.g. a metrics bean absent from DI context and passed through unconditionally.","commonSituations":"Guice/Spring module where the CollectorMetrics binding is missing; optional metrics config resolved to null; test wiring copied without the metrics line.","solutions":["Pass a concrete CollectorMetrics such as InMemoryCollectorMetrics (exposed in the server) or NOOP_METRICS.","Default before passing: metrics != null ? metrics : CollectorMetrics.NOOP_METRICS.","Fix the DI binding so a metrics implementation is always available."],"exampleFix":"// before\nbuilder.metrics(context.getBean(CollectorMetrics.class)); // null bean -> NPE\n\n// after\nCollectorMetrics m = context.getBean(CollectorMetrics.class);\nbuilder.metrics(m != null ? m : CollectorMetrics.NOOP_METRICS);","handlingStrategy":"validation","validationCode":"java\nCollectorMetrics m = (metrics != null) ? metrics : CollectorMetrics.NOOP_METRICS;\nbuilder.metrics(m);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default null metrics to NOOP_METRICS at the call site.","Provide a DI binding for CollectorMetrics."],"tags":["zipkin","java","collector","metrics","configuration"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}