{"record":{"id":"db6b0a011718ef7a","repo":"apache/beam","slug":"received-null-value-for-non-nullable-field","errorCode":null,"errorMessage":"Received null value for non-nullable field \"{}\"","messagePattern":"Received null value for non-nullable field \"(.+?)\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java","lineNumber":100,"sourceCode":"\n    Preconditions.checkArgument(\n        yamlMap instanceof Map,\n        \"Expected a YAML mapping but got type '%s' instead.\",\n        Preconditions.checkNotNull(yamlMap).getClass());\n\n    return toBeamRow(\n        (Map<String, Object>) Preconditions.checkNotNull(yamlMap), schema, convertNamesToCamelCase);\n  }\n\n  private static @Nullable Object toBeamValue(\n      Field field, @Nullable Object yamlValue, boolean convertNamesToCamelCase) {\n    FieldType fieldType = field.getType();\n\n    if (yamlValue == null) {\n      if (fieldType.getNullable()) {\n        return null;\n      } else {\n        throw new IllegalArgumentException(\n            \"Received null value for non-nullable field \\\"\" + field.getName() + \"\\\"\");\n      }\n    }\n\n    if (yamlValue instanceof String\n        || yamlValue instanceof Number\n        || yamlValue instanceof Boolean) {\n      String yamlStringValue = yamlValue.toString();\n      if (YAML_VALUE_PARSERS.containsKey(fieldType.getTypeName())) {\n        return YAML_VALUE_PARSERS.get(fieldType.getTypeName()).apply(yamlStringValue);\n      }\n    }\n\n    if (yamlValue instanceof byte[] && fieldType.getTypeName() == Schema.TypeName.BYTES) {\n      return yamlValue;\n    }\n\n    if (yamlValue instanceof List) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java#L82-L118","documentation":"YamlUtils.toBeamValue converts a single YAML value to its Beam schema representation. If the YAML value is null but the field's schema type is non-nullable, this IllegalArgumentException names the offending field, since a null cannot satisfy a required field.","triggerScenarios":"A YAML document contains a key with an explicit null value (or an omitted key mapping to null) while the corresponding schema field has getNullable() == false; recursing via toBeamRow into nested objects triggers the same check per field.","commonSituations":"YAML like `name:` (explicit null), missing nested keys defaulting to null, or schema marked required incorrectly while data legitimately contains nulls.","solutions":["Supply a value for the field in the YAML document.","Mark the field nullable in the schema if nulls are valid in the data.","Pre-validate the YAML document and fill/remove nulls for required keys before conversion.","Use defaults when deserializing so required fields never surface as null."],"exampleFix":"// before (YAML)\nname:\nage: 5\n// after\nname: anonymous\nage: 5","handlingStrategy":"validation","validationCode":"for (Map.Entry<String, Object> e : yamlMap.entrySet()) {\n  Schema.Field f = schema.getField(e.getKey());\n  if (e.getValue() == null && !f.getType().getNullable())\n    throw new IllegalArgumentException(\"null for non-nullable field: \" + f.getName());\n}","typeGuard":"boolean nullAllowed(Schema schema, String fieldName) {\n  return schema.getField(fieldName).getType().getNullable();\n}","tryCatchPattern":"try {\n  return YamlUtils.toBeamRow(yamlString, schema);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"non-nullable field\")) {\n    logger.warning(\"Null in required field: \" + e.getMessage());\n    return null; // or route to dead-letter\n  }\n  throw e;\n}","preventionTips":["Avoid explicit nulls (`key:`) in YAML for required fields","Mark schema fields nullable when data can contain nulls","Validate/normalize YAML documents before conversion"],"tags":["java","yaml","schema","null"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}