openzipkin/zipkin · error · NullPointerException
metrics == null
Error message
metrics == null
What it means
ActiveMQCollector.Builder.metrics is a required setter: passing null throws NullPointerException immediately (fail-fast contract used throughout Zipkin collectors). The metrics object is also scoped to the 'activemq' transport via CollectorMetrics.forTransport, so the collector can report messages/spans/bytes per transport.
Source
Thrown at zipkin-collector/activemq/src/main/java/zipkin2/collector/activemq/ActiveMQCollector.java:43
public static final class Builder extends CollectorComponent.Builder {
Collector.Builder delegate = Collector.newBuilder(ActiveMQCollector.class);
CollectorMetrics metrics = CollectorMetrics.NOOP_METRICS;
ActiveMQConnectionFactory connectionFactory;
String queue = "zipkin";
int concurrency = 1;
@Override public Builder storage(StorageComponent storage) {
this.delegate.storage(storage);
return this;
}
@Override public Builder sampler(CollectorSampler sampler) {
this.delegate.sampler(sampler);
return this;
}
@Override public Builder metrics(CollectorMetrics metrics) {
if (metrics == null) throw new NullPointerException("metrics == null");
this.metrics = metrics.forTransport("activemq");
this.delegate.metrics(this.metrics);
return this;
}
public Builder connectionFactory(ActiveMQConnectionFactory connectionFactory) {
if (connectionFactory == null) throw new NullPointerException("connectionFactory == null");
this.connectionFactory = connectionFactory;
return this;
}
/** Queue zipkin spans will be consumed from. Defaults to "zipkin". */
public Builder queue(String queue) {
if (queue == null) throw new NullPointerException("queue == null");
this.queue = queue;
return this;
}
View on GitHub (pinned to 878ce2a1fa)
Solutions
- Pass a real CollectorMetrics instance, at minimum CollectorMetrics.NOOP_METRICS if you don't want metrics.
- Fix the dependency wiring so the metrics binding (e.g. InMemoryCollectorMetrics for tests) is provided.
- If null came from a config lookup, default it: metrics != null ? metrics : CollectorMetrics.NOOP_METRICS.
Example fix
// before
builder.metrics(config.get("metrics")); // returns null -> NPE
// after
CollectorMetrics m = config.get("metrics");
builder.metrics(m != null ? m : CollectorMetrics.NOOP_METRICS); Defensive patterns
Strategy: validation
Validate before calling
java if (metrics == null) metrics = CollectorMetrics.NOOP_METRICS; builder.metrics(metrics);
Prevention
- Centralize collector construction in one factory that requires CollectorMetrics as a parameter.
- Bind a default CollectorMetrics in DI so it can never resolve to null.
When it happens
Trigger: Calling ActiveMQCollector.newBuilder().metrics(null) — typically when a wiring/framework config property for metrics is absent and the code forwards null unconditionally.
Common situations: DI/Guice/Spring wiring where the metrics binding is missing; copying an example that assumed an implicit default; test code that only sets storage and connectionFactory.
Related errors
AI-assisted analysis of openzipkin/zipkin@878ce2a1fa (2026-08-14).
Data as JSON: /api/errors/9020fd6f923326a2.
Report an issue: GitHub.