{"record":{"id":"57bb820c541299b6","repo":"apache/beam","slug":"value-type-is-s-for-field-type-s","errorCode":null,"errorMessage":"value type is '%s' for field type '%s'","messagePattern":"value type is '(.+?)' for field type '(.+?)'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaUtils.java","lineNumber":274,"sourceCode":"      case DOUBLE:\n      case DATETIME:\n      case BOOLEAN:\n        return Objects.toString(value);\n      case STRING:\n        {\n          String string = (String) value;\n          return \"\\\"\" + string.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\\"\", \"\\\\\\\"\") + \"\\\"\";\n        }\n      case BYTES:\n        {\n          byte[] bytes = (byte[]) value;\n          return Arrays.toString(bytes);\n        }\n      case ARRAY:\n      case ITERABLE:\n        {\n          if (!(value instanceof List)) {\n            throw new IllegalArgumentException(\n                String.format(\n                    \"value type is '%s' for field type '%s'\",\n                    value.getClass(), fieldType.getTypeName()));\n          }\n          FieldType elementType = Objects.requireNonNull(fieldType.getCollectionElementType());\n\n          @SuppressWarnings(\"unchecked\")\n          List<Object> list = (List<Object>) value;\n          if (list.isEmpty()) {\n            return \"[]\";\n          }\n          StringBuilder sb = new StringBuilder();\n          sb.append(\"[\\n\");\n          int size = list.size();\n          int index = 0;\n          for (Object element : list) {\n            sb.append(nextPrefix)\n                .append(toPrettyFieldValueString(elementType, element, nextPrefix));","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaUtils.java#L256-L292","documentation":"toPrettyFieldValueString formats a field's value for display; for ARRAY/ITERABLE field types it expects the value to be a java.util.List. If the runtime value class is not a List it throws IllegalArgumentException formatted as \"value type is '%s' for field type '%s'\". It means the value's runtime type does not match the declared field type of the schema/row.","triggerScenarios":"Calling SchemaUtils.toPrettyRowString(row, schema) (or toPrettyOptionsString/toPrettyFieldValueString directly) where an ARRAY or ITERABLE field carries a value that is not a List — e.g. a lazily-converted iterable object, a custom Iterable implementation, or a Row built with a misaligned value/type order.","commonSituations":"Constructing a Row manually with values in the wrong order so an array field receives a scalar (or a non-List collection); a custom Coder/adapter producing Iterable-backed values instead of materialized Lists; schema registry drift where the declared type says ARRAY but the producer emitted something else.","solutions":["Materialize collection values into java.util.List before building the Row (e.g. ImmutableList.copyOf(iterable)).","Verify the Row's value order/types matches the schema field order; fix the add-value calls.","Check the producer/coder that generated the value so ARRAY/ITERABLE fields always carry List values.","Catch IllegalArgumentException and inspect value.getClass() vs fieldType.getTypeName() to locate the misaligned field."],"exampleFix":"// before\nRow row = Row.withSchema(schema).addValues(myIterableNonList, \"x\").build();\nString out = SchemaUtils.toPrettyRowString(row, schema); // throws\n// after\nRow row = Row.withSchema(schema)\n    .addValues(ImmutableList.copyOf(myIterableNonList), \"x\") // array fields must be List\n    .build();\nString out = SchemaUtils.toPrettyRowString(row, schema);","handlingStrategy":"type-guard","validationCode":"for (int i = 0; i < schema.getFieldCount(); i++) {\n  Field f = schema.getField(i);\n  Object v = row.getValue(i);\n  if ((f.getType().getTypeName() == TypeName.ARRAY\n       || f.getType().getTypeName() == TypeName.ITERABLE)\n      && !(v instanceof List)) {\n    throw new IllegalStateException(\"Field \" + f.getName() + \" value is not a List: \"\n        + (v == null ? \"null\" : v.getClass()));\n  }\n}","typeGuard":"boolean isListValueForField(Object value, FieldType type) {\n  return (type.getTypeName() != TypeName.ARRAY && type.getTypeName() != TypeName.ITERABLE)\n      || value instanceof List;\n}","tryCatchPattern":"try {\n  String out = SchemaUtils.toPrettyRowString(row, schema);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"for field type\")) {\n    LOG.error(\"Row value type does not match schema field type: {}\", e.getMessage());\n    throw new RowFormatException(e);\n  }\n  throw e;\n}","preventionTips":["Always materialize ARRAY/ITERABLE values as java.util.List when building Rows.","Build Rows via a valueMap or builder that validates against the schema rather than positional addValues.","Add a round-trip test: build a Row then run toPrettyRowString in CI to catch type drift."],"tags":["java","beam","schema","type-mismatch"],"backgroundTag":"type-mismatch","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"}