{"record":{"id":"0eaa5b5f3c5f2cb4","repo":"openzipkin/zipkin","slug":"maxspancount-0","errorCode":null,"errorMessage":"maxSpanCount <= 0","messagePattern":"maxSpanCount <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"zipkin/src/main/java/zipkin2/storage/InMemoryStorage.java","lineNumber":89,"sourceCode":"    @Override public Builder strictTraceId(boolean strictTraceId) {\n      this.strictTraceId = strictTraceId;\n      return this;\n    }\n\n    @Override public Builder searchEnabled(boolean searchEnabled) {\n      this.searchEnabled = searchEnabled;\n      return this;\n    }\n\n    @Override public Builder autocompleteKeys(List<String> autocompleteKeys) {\n      if (autocompleteKeys == null) throw new NullPointerException(\"autocompleteKeys == null\");\n      this.autocompleteKeys = autocompleteKeys;\n      return this;\n    }\n\n    /** Eldest traces are removed to ensure spans in memory don't exceed this value */\n    public Builder maxSpanCount(int maxSpanCount) {\n      if (maxSpanCount <= 0) throw new IllegalArgumentException(\"maxSpanCount <= 0\");\n      this.maxSpanCount = maxSpanCount;\n      return this;\n    }\n\n    @Override public InMemoryStorage build() {\n      return new InMemoryStorage(this);\n    }\n  }\n\n  /**\n   * Primary source of data is this map, which includes spans ordered descending by timestamp. All\n   * other maps are derived from the span values here. This uses a list for the spans, so that it is\n   * visible (via /api/v2/trace/{traceId}) when instrumentation report the same spans multiple\n   * times.\n   */\n  private final SortedMultimap<TraceIdTimestamp, Span> spansByTraceIdTimestamp =\n    new SortedMultimap<TraceIdTimestamp, Span>(TIMESTAMP_DESCENDING) {\n      @Override Collection<Span> valueContainer() {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin/src/main/java/zipkin2/storage/InMemoryStorage.java#L71-L107","documentation":"InMemoryStorage.Builder.maxSpanCount(int) sets the eviction threshold for the in-memory store (eldest traces are evicted to keep span count bounded) and requires a positive value; zero or negative throws IllegalArgumentException('maxSpanCount <= 0'). This is a fail-fast configuration check at builder time, not a runtime data error.","triggerScenarios":"Calling new InMemoryStorage.Builder().maxSpanCount(0) (or a negative), usually because a config property (zipkin.storage.mem.maxSpans) failed to resolve and defaulted to 0, or arithmetic computed the value.","commonSituations":"Property name typo so the configured value never lands and an int default of 0 is passed; env-var missing in a deployment; tests parameterizing maxSpanCount with an unset value.","solutions":["Set a positive value matching expected volume (e.g. 500000) via the builder or the zipkin-server property.","Trace where the 0 came from: log the property source; fix the typo (zipkin.storage.mem.maxspans) or supply the env var.","Guard computed values: maxSpanCount(Math.max(1, configured)).","Fail startup with a clear message instead of silently defaulting unset config to 0."],"exampleFix":"# before (zipkin-server env)\n# ZIPKIN_STORAGE_MEM_MAXSPANS unset -> builder got 0\n\n# after\nZIPKIN_STORAGE_MEM_MAXSPANS=500000","handlingStrategy":"validation","validationCode":"int effective = configuredMaxSpans > 0 ? configuredMaxSpans : 500_000;\nInMemoryStorage storage = InMemoryStorage.newBuilder().maxSpanCount(effective).build();","typeGuard":"boolean isValidMaxSpanCount(int v) { return v > 0; }","tryCatchPattern":null,"preventionTips":["Fail config loading loudly when the maxSpans property is missing instead of defaulting to 0.","Smoke-test startup config in staging so builder-time checks fire before deploy."],"tags":["zipkin","configuration","in-memory-storage"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}