{"record":{"id":"bb419bc0dea8993c","repo":"openzipkin/zipkin","slug":"sampler-null","errorCode":null,"errorMessage":"sampler == null","messagePattern":"sampler == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"zipkin-collector/core/src/main/java/zipkin2/collector/Collector.java","lineNumber":73,"sourceCode":"    }\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;\n  final CollectorSampler sampler;\n  final StorageComponent storage;\n\n  Collector(Builder builder) {\n    if (builder.logger == null) throw new NullPointerException(\"logger == null\");\n    this.logger = builder.logger;\n    this.metrics = builder.metrics == null ? CollectorMetrics.NOOP_METRICS : builder.metrics;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-collector/core/src/main/java/zipkin2/collector/Collector.java#L55-L91","documentation":"Collector.Builder.sampler throws NullPointerException when passed null. As with metrics, an unset sampler defaults to CollectorSampler.ALWAYS_SAMPLE in the constructor, but an explicit null is a caller bug and fails fast. Samplers decide what fraction of trace ids are retained by the collector.","triggerScenarios":"Calling .sampler(null), commonly when a sampler built from an env string (e.g. COLLECTOR_SAMPLE_PERCENTAGE) is null because parsing code returned null on bad input.","commonSituations":"Sample-rate property missing/malformed so the factory method returns null; conditional sampler creation on a path that doesn't always run; DI binding absent.","solutions":["Build the sampler with CollectorSampler.create(rate) where rate ∈ [0,1], or omit the call to accept ALWAYS_SAMPLE default.","Default explicitly: .sampler(s != null ? s : CollectorSampler.ALWAYS_SAMPLE).","Fix the rate parsing so invalid values fail loudly at config load instead of yielding null."],"exampleFix":"// before\nFloat pct = parsePct(env.get(\"COLLECTOR_SAMPLE_PERCENTAGE\")); // null\nbuilder.sampler(pct == null ? null : CollectorSampler.create(pct)); // NPE when null\n\n// after\nbuilder.sampler(pct == null ? CollectorSampler.ALWAYS_SAMPLE : CollectorSampler.create(pct));","handlingStrategy":"validation","validationCode":"java\nCollectorSampler s = (sampler != null) ? sampler : CollectorSampler.ALWAYS_SAMPLE;\nbuilder.sampler(s);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parse sample-rate config into a float in [0,1] at load time and fail with a clear message on bad values.","Omit the sampler call entirely when you want ALWAYS_SAMPLE."],"tags":["zipkin","java","collector","sampling","configuration"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}