{"record":{"id":"07584bdd91b999ba","repo":"apache/druid","slug":"value-of-dimension-s-cannot-be-null","errorCode":null,"errorMessage":"Value of dimension[%s] cannot be null","messagePattern":"Value of dimension\\[(.+?)\\] 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":180,"sourceCode":"     *\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    /**\n     * Adds a dimension to be emitted with this metric event.\n     *\n     * @throws IAE if the dimension name or the given value is null.\n     */\n    public Builder setDimension(String dim, Object value)\n    {\n      if (dim == null) {\n        throw new IAE(\"Dimension name cannot be null\");\n      } else if (value == null) {\n        throw new IAE(\"Value of dimension[%s] cannot be null\", dim);\n      }\n\n      userDims.put(dim, value);\n      return this;\n    }\n\n    public Object getDimension(String dim)\n    {\n      return userDims.get(dim);\n    }\n\n    public Builder setMetric(String metric, Number value)\n    {\n      if (Double.isNaN(value.doubleValue())) {\n        throw new ISE(\"Value of NaN is not allowed!\");\n      }\n      if (Double.isInfinite(value.doubleValue())) {\n        throw new ISE(\"Value of Infinite is not allowed!\");","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/service/ServiceMetricEvent.java#L162-L198","documentation":"ServiceMetricEvent.Builder.setDimension(String dim, Object value) also validates the dimension VALUE: after checking the name, it rejects a null value with IAE \"Value of dimension[%s] cannot be null\". Both parts of a dimension must be present for the metric event to be well-formed.","triggerScenarios":"Calling builder.setDimension(\"host\", null) or setDimension(name, someObjectThatIsNull) — the value argument is null while the name is non-null.","commonSituations":"Emitting metrics whose dimension value comes from an optional field (e.g. task status, container id) that is null at emit time; refactors that changed a value's type and made it nullable.","solutions":["Default the value to a sentinel string like \"none\" or \"unknown\" when the source value is null.","Omit the setDimension call entirely when the value is unavailable.","Fix the producer of the value so it never returns null for this metric.","Wrap emission in a null-safe helper used by all monitor code."],"exampleFix":"// before\nString taskId = task.getId(); // may be null\nbuilder.setDimension(\"taskId\", taskId); // IAE: Value of dimension[taskId] cannot be null\n// after\nString taskId = task != null && task.getId() != null ? task.getId() : \"unknown\";\nbuilder.setDimension(\"taskId\", taskId);","handlingStrategy":"validation","validationCode":"if (value == null) { value = \"unknown\"; }\nbuilder.setDimension(name, value);","typeGuard":null,"tryCatchPattern":"try {\n  builder.setDimension(name, value);\n} catch (IllegalArgumentException e) {\n  log.warn(\"Dropping dimension [%s]: value was null\", name);\n}","preventionTips":["Default optional dimension values to a sentinel string","Skip setDimension when the value is unavailable and the metric still stands","Make the field backing the dimension non-null at construction time"],"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"}