{"record":{"id":"8bc8c230df012607","repo":"apache/beam","slug":"dynamicmessage-is-not-supported-by-the-protocoder-use-the","errorCode":null,"errorMessage":"DynamicMessage is not supported by the ProtoCoder, use the DynamicProtoCoder.","messagePattern":"DynamicMessage is not supported by the ProtoCoder, use the DynamicProtoCoder\\.","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoCoder.java","lineNumber":302,"sourceCode":"   */\n  final Set<Class<?>> extensionHostClasses;\n\n  // Transient fields that are lazy initialized and then memoized.\n  private transient volatile ExtensionRegistry memoizedExtensionRegistry;\n  transient Parser<T> memoizedParser;\n\n  /** Private constructor. */\n  protected ProtoCoder(Class<T> protoMessageClass, Set<Class<?>> extensionHostClasses) {\n    this.protoMessageClass = protoMessageClass;\n    this.extensionHostClasses = extensionHostClasses;\n  }\n\n  /** Get the memoized {@link Parser}, possibly initializing it lazily. */\n  protected synchronized Parser<T> getParser() {\n    if (memoizedParser == null) {\n      try {\n        if (DynamicMessage.class.equals(protoMessageClass)) {\n          throw new IllegalArgumentException(\n              \"DynamicMessage is not supported by the ProtoCoder, use the DynamicProtoCoder.\");\n        } else {\n          @SuppressWarnings(\"unchecked\")\n          T protoMessageInstance =\n              (T) protoMessageClass.getMethod(\"getDefaultInstance\").invoke(null);\n          @SuppressWarnings(\"unchecked\")\n          Parser<T> tParser = (Parser<T>) protoMessageInstance.getParserForType();\n          memoizedParser = tParser;\n        }\n      } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {\n        throw new IllegalArgumentException(e);\n      }\n    }\n    return memoizedParser;\n  }\n\n  /**\n   * Returns a {@link CoderProvider} which uses the {@link ProtoCoder} for {@link Message proto","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoCoder.java#L284-L320","documentation":"ProtoCoder requires a concrete protobuf-generated Message class so it can obtain a Parser via getDefaultInstance(). DynamicMessage has no such static factory and needs a Descriptor, so ProtoCoder deliberately rejects it and directs users to DynamicProtoCoder.","triggerScenarios":"Creating ProtoCoder.of(DynamicMessage.class) (or a coderFor/type inference resolving to DynamicMessage) and then decoding, or any path that calls getParser() with protoMessageClass == DynamicMessage.","commonSituations":"Working with dynamically parsed protos (e.g. from descriptors read at runtime) but picking the wrong coder class; copying coder code from examples that used DynamicMessage with parseFrom.","solutions":["Use DynamicProtoCoder instead of ProtoCoder for DynamicMessage types.","If the type is known at compile time, use the generated message class with ProtoCoder.of(GeneratedMessage.class).","If relying on automatic coder inference, ensure the PCollection's TypeDescriptor points at the concrete generated class."],"exampleFix":"// before\nProtoCoder<DynamicMessage> coder = ProtoCoder.of(DynamicMessage.class);\n// after\nDynamicProtoCoder<DynamicMessage> coder = DynamicProtoCoder.of(descriptor);","handlingStrategy":"type-guard","validationCode":"if (DynamicMessage.class.equals(type.getRawType())) {\n  throw new IllegalArgumentException(\"use DynamicProtoCoder\");\n}","typeGuard":"boolean isDynamic = msg instanceof DynamicMessage; // route to DynamicProtoCoder if true","tryCatchPattern":"try { coder = ProtoCoder.of(clazz); } catch (IllegalArgumentException e) { coder = DynamicProtoCoder.of(descriptor); }","preventionTips":["Use DynamicProtoCoder for descriptor-based messages.","Keep TypeDescriptors pointing at concrete generated classes.","Check coder type before applying schema conversions."],"tags":["java","protobuf","coder"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}