{"record":{"id":"cdf4c6650d44d3bd","repo":"apache/beam","slug":"field-s-not-nullable","errorCode":null,"errorMessage":"Field %s not nullable","messagePattern":"Field (.+?) not nullable","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java","lineNumber":114,"sourceCode":"      }\n      printer.println();\n    } catch (IOException e) {\n      throw new IllegalArgumentException(\"encodeRecord failed!\", e);\n    }\n    return writer.toString();\n  }\n\n  /**\n   * Attempt to cast an object to a specified Schema.Field.Type.\n   *\n   * @throws IllegalArgumentException if the value cannot be cast to that type.\n   * @return The casted object in Schema.Field.Type.\n   */\n  public static Object autoCastField(Schema.Field field, @Nullable Object rawObj) {\n    // handle null\n    if (rawObj == null) {\n      if (!field.getType().getNullable()) {\n        throw new IllegalArgumentException(String.format(\"Field %s not nullable\", field.getName()));\n      }\n      return null;\n    }\n\n    FieldType type = field.getType();\n    // handle NlsString\n    if (CalciteUtils.isStringType(type)) {\n      if (rawObj instanceof NlsString) {\n        return ((NlsString) rawObj).getValue();\n      } else {\n        return rawObj;\n      }\n      // handle date/time\n    } else if (CalciteUtils.DATE.typesEqual(type) || CalciteUtils.NULLABLE_DATE.typesEqual(type)) {\n      if (rawObj instanceof GregorianCalendar) { // used by the SQL CLI\n        GregorianCalendar calendar = (GregorianCalendar) rawObj;\n        return Instant.ofEpochMilli(calendar.getTimeInMillis())\n            .atZone(calendar.getTimeZone().toZoneId())","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java#L96-L132","documentation":"autoCastField enforces the row schema's nullability contract: when a field value is null but the declared Schema.Field.Type is not nullable, it throws IllegalArgumentException. It is a schema-validation guard fired from csvLines2BeamRows when incoming CSV data contains an empty/missing value for a column the Beam schema marks as non-nullable.","triggerScenarios":"A CSV record contains an empty/missing value for a field whose Schema.Field.Type has nullable=false — e.g. an empty cell for a required INT column.","commonSituations":"Missing values in real-world CSV data; schema built with non-nullable fields by default while data has gaps.","solutions":["Make the field nullable in the schema (FieldType nullable true) if nulls are acceptable","Clean the input data to fill or remove null values before parsing","Filter rows containing nulls for required fields before csvLines2BeamRows"],"exampleFix":"// before\nSchema.Field.of(\"age\", Schema.FieldType.INT32) // non-nullable by default\n// after\nSchema.Field.of(\"age\", Schema.FieldType.INT32.withNullable(true))","handlingStrategy":"validation","validationCode":"if (rawValue == null && !field.getType().getNullable()) { throw new IllegalArgumentException(\"missing required field \" + field.getName()); }","typeGuard":"boolean acceptsNull(Schema.Field f) { return f.getType().getNullable(); }","tryCatchPattern":"try { row = BeamTableUtils.csvLines2BeamRows(line, schema, format); } catch (IllegalArgumentException e) { /* route row to dead-letter */ }","preventionTips":["Declare nullable=true for fields that may be missing in CSV","Clean or impute nulls before parsing","Drop dead-letter records with nulls in required fields"],"tags":["csv","schema","null"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T08:17:22.691Z"}