{"record":{"id":"fc44748d36dc2b8a","repo":"apache/druid","slug":"cannot-return-null-value-as-double","errorCode":null,"errorMessage":"Cannot return null value as double","messagePattern":"Cannot return null value as double","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java","lineNumber":50,"sourceCode":"{\n  private static final NilColumnValueSelector INSTANCE = new NilColumnValueSelector();\n\n  public static NilColumnValueSelector instance()\n  {\n    return INSTANCE;\n  }\n\n  private NilColumnValueSelector()\n  {\n  }\n\n  /**\n   * always throws an exception, all values in this column are null\n   */\n  @Override\n  public double getDouble()\n  {\n    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\");","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java#L32-L68","documentation":"NilColumnValueSelector represents a column whose every value is null. Since primitives cannot be null in Java, getDouble() throws IllegalStateException instead of returning a value. Callers must check isNull()/getObject() before requesting primitive access on a null column.","triggerScenarios":"Calling getDouble() on a column selector created by NilColumnValueSelector — e.g. querying a numeric column that does not exist in a row/segment, or accessing a typed selector on rows lacking the value.","commonSituations":"Queries against datasources where a numeric column is absent in some segments; row-based ingestion where rows omit a numeric field; misconfigured query columns pointing at nonexistent metrics.","solutions":["Check selector.isNull() or use getObject() and handle null before calling getDouble()","Ensure the queried column exists in the datasource/segment (verify with SegmentMetadataQuery)","Use default value handling in the query (e.g. SQL COALESCE) so missing columns are substituted","If ingesting, supply a default for the numeric field in the ingestion spec"],"exampleFix":"// before\ndouble d = selector.getDouble();\n// after\nObject val = selector.isNull() ? null : selector.getObject();\ndouble d = val == null ? 0.0 : ((Number) val).doubleValue();","handlingStrategy":"type-guard","validationCode":"if (selector.getObject() == null) { /* treat as missing */ }","typeGuard":"Double safeGetDouble(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getDouble(); }","tryCatchPattern":"try {\n  double d = selector.getDouble();\n} catch (IllegalStateException e) {\n  double d = 0.0; // default for null column\n}","preventionTips":["Always call isNull() before primitive getters on selectors","Use SQL COALESCE for possibly-missing numeric columns","Verify column existence in datasource schema before querying"],"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"}