{"record":{"id":"c78947adf3905a71","repo":"apache/druid","slug":"cannot-return-null-value-as-long","errorCode":null,"errorMessage":"Cannot return null value as long","messagePattern":"Cannot return null value as long","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java","lineNumber":68,"sourceCode":"    throw new IllegalStateException(\"Cannot return null value as double\");\n  }\n\n  /**\n   * always throws an exception, all values in this column are null\n   */\n  @Override\n  public float getFloat()\n  {\n    throw new IllegalStateException(\"Cannot return null value as float\");\n  }\n\n  /**\n   * always throws an exception, all values in this column are null\n   */\n  @Override\n  public long getLong()\n  {\n    throw new IllegalStateException(\"Cannot return null value as long\");\n  }\n\n  /**\n   * Always returns null.\n   */\n  @Nullable\n  @Override\n  public Object getObject()\n  {\n    return null;\n  }\n\n  /**\n   * Returns Object.class.\n   */\n  @Override\n  public Class classOfObject()\n  {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java#L50-L86","documentation":"NilColumnValueSelector.getLong() throws IllegalStateException since all values in the column are null and long primitives cannot express null. The selector intentionally fails fast instead of silently returning 0. Check null status before primitive access.","triggerScenarios":"Calling getLong() on a selector for a fully-null long column — e.g. a missing metric column in a segment or rows omitting the field.","commonSituations":"Queries against datasources where the long metric is missing in some segments; row-based ingestion with absent fields; typo'd column names in queries.","solutions":["Use isNull()/getObject() before calling getLong()","Confirm the column exists (SegmentMetadataQuery or datasource schema)","Apply SQL COALESCE or query defaults for missing columns","Set default values for long fields in the ingestion spec"],"exampleFix":"// before\nlong l = selector.getLong();\n// after\nlong l = selector.isNull() ? 0L : ((Number) selector.getObject()).longValue();","handlingStrategy":"type-guard","validationCode":"if (selector.isNull()) { /* handle missing */ }","typeGuard":"Long safeGetLong(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getLong(); }","tryCatchPattern":"try {\n  long l = selector.getLong();\n} catch (IllegalStateException e) {\n  long l = 0L;\n}","preventionTips":["Check isNull() before getLong()","Use getObject() and null-check for nullable long metrics","Validate column names against the datasource schema"],"tags":["null-value","column-selector","numeric"],"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"}