{"record":{"id":"66f923125181174f","repo":"apache/druid","slug":"dimension-name-cannot-be-null","errorCode":null,"errorMessage":"Dimension name cannot be null","messagePattern":"Dimension name cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/emitter/service/ServiceMetricEvent.java","lineNumber":152,"sourceCode":"   */\n  public static class Builder extends ServiceEventBuilder<ServiceMetricEvent>\n  {\n    private final Map<String, Object> userDims = new TreeMap<>();\n    private String feed = \"metrics\";\n    private String metric;\n    private Number value;\n    private DateTime createdTime;\n\n    public Builder setFeed(String feed)\n    {\n      this.feed = feed;\n      return this;\n    }\n\n    public Builder setDimension(String dim, String[] values)\n    {\n      if (dim == null) {\n        throw new IAE(\"Dimension name cannot be null\");\n      }\n\n      userDims.put(dim, Arrays.asList(values));\n      return this;\n    }\n\n    /**\n     * Adds a dimension to be emitted with this metric event, only if the given\n     * value is not null.\n     *\n     * @throws IAE if the dimension name is null.\n     */\n    public Builder setDimensionIfNotNull(String dim, Object value)\n    {\n      return value == null ? this : setDimension(dim, value);\n    }\n\n    /**","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/service/ServiceMetricEvent.java#L134-L170","documentation":"ServiceMetricEvent.Builder.setDimension(String dim, String[] values) validates that the dimension name is non-null before adding it to the event's dimension map. A null dimension name would produce a malformed metric event that downstream consumers cannot key on, so IAE is thrown eagerly.","triggerScenarios":"Calling builder.setDimension(null, new String[]{...}) with a null dimension name. Note this is the String[] overload; the check fires only on a null dim name, not null values.","commonSituations":"Metric-emitting code that computes a dimension name dynamically (e.g. from a task ID or label) and gets null when the source value is missing; monitor code emitting service metrics during Druid startup before identifiers are known.","solutions":["Fix the caller to pass a non-null dimension name; trace where the name is computed and supply a default.","Substitute a placeholder like \"unknown\" when the dimension source value is null.","Skip adding the dimension (or the whole event) when the name is unavailable, if the metric remains meaningful.","Add an upstream null-check with a clear log message so the root cause is visible."],"exampleFix":"// before\nString dataSource = taskInfo == null ? null : taskInfo.getDataSource();\nbuilder.setDimension(dataSource, new String[]{\"task\"}); // IAE if null\n// after\nString dataSource = taskInfo == null ? null : taskInfo.getDataSource();\nbuilder.setDimension(dataSource != null ? dataSource : \"unknown\", new String[]{\"task\"});","handlingStrategy":"validation","validationCode":"if (dimName == null) { dimName = \"unknown\"; }\nbuilder.setDimension(dimName, values);","typeGuard":null,"tryCatchPattern":"try {\n  builder.setDimension(dim, values);\n} catch (IllegalArgumentException e) {\n  log.warn(e, \"Skipping metric with null dimension\");\n}","preventionTips":["Default dynamically derived dimension names to a non-null constant","Null-check any lookup that feeds dimension names","Cover metric-emitting code paths with tests where source fields may be missing"],"tags":["metrics","null","validation","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}