{"record":{"id":"f4bea33b2e09fbc7","repo":"apache/beam","slug":"received-an-empty-yaml-string-but-output-schema-contains","errorCode":null,"errorMessage":"Received an empty YAML string, but output schema contains required fields: %s","messagePattern":"Received an empty YAML string, but output schema contains required fields: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java","lineNumber":74,"sourceCode":"          .put(Schema.TypeName.STRING, str -> str)\n          .put(Schema.TypeName.BYTES, str -> BaseEncoding.base64().decode(str))\n          .build();\n\n  public static Row toBeamRow(@Nullable String yamlString, Schema schema) {\n    return toBeamRow(yamlString, schema, false);\n  }\n\n  public static Row toBeamRow(\n      @Nullable String yamlString, Schema schema, boolean convertNamesToCamelCase) {\n    if (yamlString == null || yamlString.isEmpty()) {\n      List<Field> requiredFields =\n          schema.getFields().stream()\n              .filter(field -> !field.getType().getNullable())\n              .collect(Collectors.toList());\n      if (requiredFields.isEmpty()) {\n        return Row.nullRow(schema);\n      } else {\n        throw new IllegalArgumentException(\n            String.format(\n                \"Received an empty YAML string, but output schema contains required fields: %s\",\n                requiredFields));\n      }\n    }\n    Yaml yaml = new Yaml();\n    Object yamlMap = yaml.load(yamlString);\n\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(","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java#L56-L92","documentation":"YamlUtils.toBeamRow converts a YAML string to a Beam Row. An empty/blank YAML string yields no mapping, which is acceptable only if every field in the target schema is nullable (producing Row.nullRow). If the schema has any non-nullable (required) fields, this IllegalArgumentException is thrown listing them.","triggerScenarios":"Calling YamlUtils.toBeamRow(\"\" or blank string, schema) where schema.getFields() contains at least one field with type.getNullable() == false.","commonSituations":"Parsing empty YAML documents/files or whitespace-only strings from sources (empty config files, blank lines read as documents) into rows with required fields.","solutions":["Provide a non-empty YAML mapping containing values for all required fields.","Make the schema fields nullable if an empty document is legitimately representable.","Check for empty input before calling toBeamRow and skip or default it.","Fix upstream file reads that return empty strings for missing files."],"exampleFix":"// before\nRow row = YamlUtils.toBeamRow(\"\", schema); // schema has required fields\n// after\nif (yamlString.trim().isEmpty()) {\n  yamlString = \"name: default\\nage: 0\"; // or make schema fields nullable\n}\nRow row = YamlUtils.toBeamRow(yamlString, schema);","handlingStrategy":"validation","validationCode":"if (yamlString == null || yamlString.trim().isEmpty()) {\n  List<String> required = schema.getFields().stream()\n      .filter(f -> !f.getType().getNullable())\n      .map(Schema.Field::getName)\n      .collect(Collectors.toList());\n  if (!required.isEmpty()) throw new IllegalArgumentException(\"Empty YAML, required: \" + required);\n}","typeGuard":"boolean canBeEmptyYaml(Schema schema) {\n  return schema.getFields().stream().allMatch(f -> f.getType().getNullable());\n}","tryCatchPattern":"try {\n  return YamlUtils.toBeamRow(yamlString, schema);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"empty YAML string\")) {\n    return substituteDefaultRow(schema); // fill required defaults\n  }\n  throw e;\n}","preventionTips":["Check YAML input for emptiness before conversion","Only mark schema fields non-nullable when data guarantees values","Guard file reads against returning empty strings for missing files"],"tags":["java","yaml","schema","validation"],"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"}