{"record":{"id":"3565fd43a73daf49","repo":"apache/beam","slug":"failed-to-decode-schema-due-to-an-error-decoding-field-proto","errorCode":null,"errorMessage":"Failed to decode Schema due to an error decoding Field proto:\n\n+protoField","messagePattern":"Failed to decode Schema due to an error decoding Field proto:\n\n\\+protoField","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java","lineNumber":310,"sourceCode":"        builder.setAtomicType(SchemaApi.AtomicType.BOOLEAN);\n        break;\n      case BYTES:\n        builder.setAtomicType(SchemaApi.AtomicType.BYTES);\n        break;\n    }\n    builder.setNullable(fieldType.getNullable());\n    return builder.build();\n  }\n\n  public static Schema schemaFromProto(SchemaApi.Schema protoSchema) {\n    Schema.Builder builder = Schema.builder();\n    Map<String, Integer> encodingLocationMap = Maps.newHashMap();\n    for (SchemaApi.Field protoField : protoSchema.getFieldsList()) {\n      Field field;\n      try {\n        field = fieldFromProto(protoField);\n      } catch (Exception e) {\n        throw new IllegalArgumentException(\n            \"Failed to decode Schema due to an error decoding Field proto:\\n\\n\" + protoField, e);\n      }\n      builder.addField(field);\n      encodingLocationMap.put(protoField.getName(), protoField.getEncodingPosition());\n    }\n    builder.setOptions(optionsFromProto(protoSchema.getOptionsList()));\n    Schema schema = builder.build();\n\n    Preconditions.checkState(encodingLocationMap.size() == schema.getFieldCount());\n    long distinctEncodingPositions = encodingLocationMap.values().stream().distinct().count();\n    Preconditions.checkState(distinctEncodingPositions <= schema.getFieldCount());\n    if (distinctEncodingPositions < schema.getFieldCount() && schema.getFieldCount() > 0) {\n      // This means that encoding positions were not specified in the proto. Generally, we don't\n      // expect this to happen,\n      // but if it does happen, we expect none to be specified - in which case the should all be\n      // zero.\n      Preconditions.checkState(distinctEncodingPositions == 1);\n    } else if (protoSchema.getEncodingPositionsSet()) {","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java#L292-L328","documentation":"schemaFromProto wraps any failure while translating a single Field proto into an IllegalArgumentException with the message 'Failed to decode Schema due to an error decoding Field proto' plus the proto's text form. The original exception (e.g. bad logical type, unknown atomic type) is attached as the cause.","triggerScenarios":"Decoding a serialized Schema (schemaFromProto / fromProto on rows) where at least one Field proto is malformed: unknown type name, unsupported options, or nested field translation failure (see errors 303-309).","commonSituations":"Cross-version Beam data exchange where a newer field type was serialized and an older SDK cannot decode it; manually constructed/edited schema protos; corrupted pipeline state.","solutions":["Inspect the cause exception printed below the message; it identifies the exact failing field type.","Ensure the SDK version decoding the data is >= the version that encoded it (or compatible schema capabilities).","Check the field's type_name/urn in the proto; replace unsupported or hand-edited field definitions.","Catch the IllegalArgumentException when decoding untrusted/older payloads and treat the record as unparseable."],"exampleFix":"// before\nSchema s = SchemaTranslation.schemaFromProto(suspiciousProto);\n// after\ntry { Schema s = SchemaTranslation.schemaFromProto(proto); }\ncatch (IllegalArgumentException e) { LOG.error(\"Bad field: {}\", e.getMessage(), e.getCause()); }\n","handlingStrategy":"try-catch","validationCode":"protoSchema.getFieldsList().forEach(f -> {\n  if (f.getName().isEmpty() || !f.hasFieldType())\n    throw new IllegalArgumentException(\"Malformed field: \" + f);\n});","typeGuard":null,"tryCatchPattern":"try {\n  Schema s = SchemaTranslation.schemaFromProto(proto);\n} catch (IllegalArgumentException e) {\n  LOG.error(\"Field decode failed: {} cause: {}\", e.getMessage(), e.getCause());\n  throw new DataFormatException(\"Undecodable schema\", e);\n}","preventionTips":["Match Beam versions between schema producers and consumers.","Never hand-edit serialized schema protos.","Always log the cause exception, not just the wrapper message.","Add round-trip tests: schemaToProto(schemaFromProto(s)) equals s."],"tags":["java","apache-beam","protobuf","schema"],"backgroundTag":"protobuf-unmarshal-failed","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"}