{"record":{"id":"e0eef9407f93d886","repo":"apache/druid","slug":"cannot-return-null-value-as-float","errorCode":null,"errorMessage":"Cannot return null value as float","messagePattern":"Cannot return null value as float","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java","lineNumber":59,"sourceCode":"  {\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\");\n  }\n\n  /**\n   * Always returns null.\n   */\n  @Nullable\n  @Override\n  public Object getObject()\n  {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/NilColumnValueSelector.java#L41-L77","documentation":"NilColumnValueSelector.getFloat() throws IllegalStateException because every value in this column is null and there is no valid float to return. Java primitives cannot represent null, so the selector signals the error rather than returning 0. Callers must test for null before primitive access.","triggerScenarios":"Calling getFloat() on a selector from a fully-null column — e.g. a missing float column in a segment or a row lacking that field in row-based ingestion.","commonSituations":"Queries referencing float columns absent from some segments; ingestion rows missing float fields; queries against empty datasources.","solutions":["Check isNull() or read via getObject() and convert defensively","Verify the float column exists in the segment/datasource before querying","Use query-level defaulting (SQL COALESCE) for missing columns","Provide defaults for float fields during ingestion"],"exampleFix":"// before\nfloat f = selector.getFloat();\n// after\nfloat f = selector.isNull() ? 0.0f : ((Number) selector.getObject()).floatValue();","handlingStrategy":"type-guard","validationCode":"if (selector.isNull()) { /* handle missing */ }","typeGuard":"Float safeGetFloat(ColumnValueSelector<?> s) { return s.isNull() ? null : s.getFloat(); }","tryCatchPattern":"try {\n  float f = selector.getFloat();\n} catch (IllegalStateException e) {\n  float f = 0.0f;\n}","preventionTips":["Check isNull() before getFloat()","Provide defaults for float fields at ingestion time","Confirm float columns exist across all queried segments"],"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"}