{"record":{"id":"30f1dc526e86f336","repo":"apache/beam","slug":"must-either-have-a-non-empty-list-of-pcollections-or-must","errorCode":null,"errorMessage":"must either have a non-empty list of PCollections, or must first call empty(Pipeline)","messagePattern":"must either have a non-empty list of PCollections, or must first call empty\\(Pipeline\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionList.java","lineNumber":97,"sourceCode":"  public static <T> PCollectionList<T> of(PCollection<T> pc) {\n    return new PCollectionList<T>(pc.getPipeline()).and(pc);\n  }\n\n  /**\n   * Returns a {@link PCollectionList} containing the given {@link PCollection PCollections}, in\n   * order.\n   *\n   * <p>The argument list cannot be empty.\n   *\n   * <p>All the {@link PCollection PCollections} in the resulting {@link PCollectionList} must be\n   * part of the same {@link Pipeline}.\n   *\n   * <p>Longer PCollectionLists can be created by calling {@link #and} on the result.\n   */\n  public static <T> PCollectionList<T> of(Iterable<PCollection<T>> pcs) {\n    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<>(","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionList.java#L79-L115","documentation":"PCollectionList.of(Iterable) requires at least one PCollection. An empty iterable cannot determine the owning Pipeline, so the constructor path throws IllegalArgumentException telling the caller to use PCollectionList.empty(pipeline) instead.","triggerScenarios":"Calling PCollectionList.of(Collections.emptyList()) or of an iterable filtered down to zero PCollections.","commonSituations":"Dynamically building a list of inputs where all candidate PCollections were filtered out; refactoring from PCollectionList.empty to of without ensuring non-emptiness.","solutions":["Ensure the iterable passed to of() contains at least one PCollection","Use PCollectionList.empty(pipeline) when you intentionally have no PCollections, then add with and(...)","Check the collection with iterator().hasNext() or isEmpty() before calling of()"],"exampleFix":"// before\nPCollectionList<T> list = PCollectionList.of(maybeEmpty); // throws when empty\n// after\nPCollectionList<T> list = maybeEmpty.iterator().hasNext()\n    ? PCollectionList.of(maybeEmpty)\n    : PCollectionList.empty(pipeline);","handlingStrategy":"validation","validationCode":"if (pcs == null || !pcs.iterator().hasNext()) { return PCollectionList.empty(pipeline); }","typeGuard":"boolean nonEmpty(List<PCollection<T>> pcs) { return pcs != null && !pcs.isEmpty(); }","tryCatchPattern":"try { return PCollectionList.of(pcs); } catch (IllegalArgumentException e) { return PCollectionList.empty(pipeline); }","preventionTips":["Check isEmpty() before PCollectionList.of","Use PCollectionList.empty(pipeline) for the zero-case","Handle filtered-out collections explicitly in dynamic pipeline builders"],"tags":["java","apache-beam","illegal-argument","empty-collection"],"backgroundTag":"empty-required-field","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"}