{"record":{"id":"3475111af2da57cd","repo":"apache/beam","slug":"element-argument-type-does-not-work-with-expected-schema","errorCode":null,"errorMessage":"Element argument type {} does not work with expected schema field type {}","messagePattern":"Element argument type (.+?) does not work with expected schema field type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java","lineNumber":160,"sourceCode":"                + outputSchema);\n      }\n    }\n    return new ConvertedSchemaInformation<>(outputSchemaCoder, unboxedType);\n  }\n\n  /**\n   * Returns a function to convert a Row into a primitive type. This only works when the row schema\n   * contains a single field, and that field is convertible to the primitive type.\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static <OutputT> SerializableFunction<?, OutputT> getConvertPrimitive(\n      FieldType fieldType,\n      TypeDescriptor<?> outputTypeDescriptor,\n      TypeConversionsFactory typeConversionsFactory) {\n    FieldType expectedFieldType =\n        StaticSchemaInference.fieldFromType(outputTypeDescriptor, JavaFieldTypeSupplier.INSTANCE);\n    if (!expectedFieldType.equals(fieldType)) {\n      throw new IllegalArgumentException(\n          \"Element argument type \"\n              + outputTypeDescriptor\n              + \" does not work with expected schema field type \"\n              + fieldType);\n    }\n\n    Type expectedInputType =\n        typeConversionsFactory.createTypeConversion(false).convert(outputTypeDescriptor);\n\n    TypeDescriptor<?> outputType = outputTypeDescriptor;\n    if (outputType.getRawType().isPrimitive()) {\n      // A SerializableFunction can only return an Object type, so if the DoFn parameter is a\n      // primitive type, then box it for the return. The return type will be unboxed before being\n      // forwarded to the DoFn parameter.\n      outputType = TypeDescriptor.of(Primitives.wrap(outputType.getRawType()));\n    }\n\n    TypeDescription.Generic genericType =","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java#L142-L178","documentation":"getConvertPrimitive validates that the element argument's output type descriptor corresponds exactly to the schema field type it will populate. StaticSchemaInference re-infers the FieldType from the type descriptor, and any mismatch (e.g. logical vs primitive, different nullability, DATETIME vs LONG) throws IllegalArgumentException. This guards against silently inserting a wrong-typed converter.","triggerScenarios":"Registering a primitive field conversion where the Java element type (e.g. Integer vs Long, String vs Instant) does not produce the same FieldType as the schema field; mismatched logical-type wrappers.","commonSituations":"Changing a schema field from INTEGER to INT64 without updating the conversion lambda's type; using java.util.Date where Beam expects Instant; annotation Schema mismatches between declared and actual types.","solutions":["Change the conversion's TypeDescriptor/generic type so it matches the field type exactly (e.g. use Long for INT64 fields).","Or update the schema field type to match the element argument type.","If using a logical type, ensure the element descriptor maps to the same FieldType (same logical type identifier)."],"exampleFix":"// before\n.apply(\"id\", Convert.from(Integer.class)) // field is INT64\n// after\n.apply(\"id\", Convert.from(Long.class))","handlingStrategy":"type-guard","validationCode":"FieldType expected = StaticSchemaInference.fieldFromType(TypeDescriptor.of(Integer.class), JavaFieldTypeSupplier.INSTANCE);\nif (!expected.equals(schema.getField(\"id\").getType())) { /* fix conversion type or field type */ }","typeGuard":"static <T> boolean matchesFieldType(TypeDescriptor<T> d, FieldType f) { return StaticSchemaInference.fieldFromType(d, JavaFieldTypeSupplier.INSTANCE).equals(f); }","tryCatchPattern":"try { applyConvert(...); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"does not work with expected schema field type\")) { /* align types */ } throw e; }","preventionTips":["Mirror schema field types (INT64->Long, STRING->String, DATETIME->ReadableInstant/Instant) exactly in conversions.","Rerun schema inference tests whenever field types change.","Avoid java.util.Date and other unmapped time types in schema types."],"tags":["java","schema","type-mismatch","conversion"],"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"}