{"record":{"id":"8fd71027ac299354","repo":"apache/beam","slug":"pcollections-come-from-different-pipelines-pcollectionlist","errorCode":null,"errorMessage":"PCollections come from different Pipelines","messagePattern":"PCollections come from different Pipelines","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionList.java","lineNumber":113,"sourceCode":"    Iterator<PCollection<T>> pcsIter = pcs.iterator();\n    if (!pcsIter.hasNext()) {\n      throw new IllegalArgumentException(\n          \"must either have a non-empty list of PCollections, \"\n              + \"or must first call empty(Pipeline)\");\n    }\n    return new PCollectionList<T>(pcsIter.next().getPipeline()).and(pcs);\n  }\n\n  /**\n   * Returns a new {@link PCollectionList} that has all the {@link PCollection PCollections} of this\n   * {@link PCollectionList} plus the given {@link PCollection} appended to the end.\n   *\n   * <p>All the {@link PCollection PCollections} in the resulting {@link PCollectionList} must be\n   * part of the same {@link Pipeline}.\n   */\n  public PCollectionList<T> and(PCollection<T> pc) {\n    if (pc.getPipeline() != pipeline) {\n      throw new IllegalArgumentException(\"PCollections come from different Pipelines\");\n    }\n    return new PCollectionList<>(\n        pipeline,\n        ImmutableList.<TaggedPValue>builder()\n            .addAll(pcollections)\n            .add(TaggedPValue.of(new TupleTag<T>(Integer.toString(pcollections.size())), pc))\n            .build());\n  }\n\n  /**\n   * Returns a new {@link PCollectionList} that has all the {@link PCollection PCollections} of this\n   * {@link PCollectionList} plus the given {@link PCollection PCollections} appended to the end, in\n   * order.\n   *\n   * <p>All the {@link PCollection PCollections} in the resulting {@link PCollectionList} must be\n   * part of the same {@link Pipeline}.\n   */\n  public PCollectionList<T> and(Iterable<PCollection<T>> pcs) {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionList.java#L95-L131","documentation":"PCollectionList.and(PCollection) requires every added PCollection to belong to the same Pipeline as the list. Beam PCollections cannot be mixed across Pipelines, so a mismatch throws IllegalArgumentException immediately.","triggerScenarios":"Appending a PCollection produced by a different Pipeline object (identity comparison pc.getPipeline() != pipeline) to an existing PCollectionList.","commonSituations":"Building inputs from two separately-constructed Pipelines; accidentally re-creating a Pipeline in a helper method and mixing its outputs with the main pipeline's; combining test pipeline outputs with production ones.","solutions":["Ensure all PCollections come from the same Pipeline instance before combining","Pass the Pipeline into helper methods so they create PCollections from the correct Pipeline","Re-create the downstream transforms on the same Pipeline instead of crossing pipelines"],"exampleFix":"// before\nPCollection<T> other = otherPipeline.apply(...);\nlist.and(other); // IllegalArgumentException\n// after\nPCollection<T> other = samePipeline.apply(...);\nlist.and(other);","handlingStrategy":"validation","validationCode":"if (pc.getPipeline() != list.getPipeline()) { throw new IllegalArgumentException(\"wrong pipeline\"); }","typeGuard":"boolean samePipeline(PCollection<?> pc, Pipeline p) { return pc.getPipeline() == p; }","tryCatchPattern":"try { return list.and(pc); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"PCollection from different Pipeline\", e); }","preventionTips":["Thread a single Pipeline instance through all pipeline-building code","Never create ad-hoc Pipelines inside helper methods","Assert pipeline identity in shared builder utilities"],"tags":["java","apache-beam","pipeline","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}