{"record":{"id":"c4988c839862aefd","repo":"apache/beam","slug":"output-coders-were-already-specified","errorCode":null,"errorMessage":"Output coders were already specified","messagePattern":"Output coders were already specified","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonExternalTransform.java","lineNumber":265,"sourceCode":"    if (typeHints.containsKey(argType)) {\n      throw new IllegalArgumentException(\n          String.format(\"typehint for arg type %s already exists\", argType));\n    }\n    typeHints.put(argType, fieldType);\n    return this;\n  }\n\n  /**\n   * Specifies the keys and {@link Coder}s of the output {@link PCollection}s produced by this\n   * transform.\n   *\n   * @param outputCoders a mapping from output keys to {@link Coder}s.\n   * @return updated wrapper for the cross-language transform.\n   */\n  public PythonExternalTransform<InputT, OutputT> withOutputCoders(\n      Map<String, Coder<?>> outputCoders) {\n    if (this.outputCoders.size() > 0) {\n      throw new IllegalArgumentException(\"Output coders were already specified\");\n    }\n    this.outputCoders.putAll(outputCoders);\n    return this;\n  }\n\n  /**\n   * Specifies the {@link Coder} of the output {@link PCollection}s produced by this transform.\n   * Should only be used if this transform produces a single output.\n   *\n   * @param outputCoder output {@link Coder} of the transform.\n   * @return updated wrapper for the cross-language transform.\n   */\n  public PythonExternalTransform<InputT, OutputT> withOutputCoder(Coder<?> outputCoder) {\n    if (this.outputCoders.size() > 0) {\n      throw new IllegalArgumentException(\"Output coders were already specified\");\n    }\n\n    // Output key should not matter when only specifying a single output.","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonExternalTransform.java#L247-L283","documentation":"withOutputCoders sets the map of output PCollection coders for the cross-language transform. The library throws IllegalArgumentException if output coders were already specified on this builder, since redefining the coder map would silently discard previously configured coders. Coders can only be set once per transform instance.","triggerScenarios":"Calling withOutputCoders(Map) when this.outputCoders is non-empty — i.e. after a prior withOutputCoders or withOutputCoder call on the same PythonExternalTransform.","commonSituations":"Chaining both withOutputCoder(...) and withOutputCoders(...); calling withOutputCoders twice in a fluent chain; reusing a pre-configured transform object in two pipelines.","solutions":["Remove the duplicate coder-setting call and keep a single withOutputCoders invocation","Combine all coders into one map and pass it in a single call","Build a fresh PythonExternalTransform if you need a different coder configuration"],"exampleFix":"// before\next.withOutputCoder(myCoder).withOutputCoders(coderMap); // throws\n// after\next.withOutputCoders(coderMap); // single specification","handlingStrategy":"validation","validationCode":"if (outputCoders != null && !outputCoders.isEmpty()) {\n  throw new IllegalStateException(\"output coders already set\");\n}\ntransform.withOutputCoders(outputCoders);","typeGuard":null,"tryCatchPattern":"try {\n  transform.withOutputCoders(map);\n} catch (IllegalArgumentException e) {\n  // coders already set; reuse existing configuration\n}","preventionTips":["Call withOutputCoders or withOutputCoder exactly once, never both","Build the full coder map first, then set it in a single call","Treat PythonExternalTransform builders as single-use"],"tags":["java","beam","cross-language","coders","illegal-state"],"backgroundTag":"conflicting-config-options","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"}