{"record":{"id":"665dbd174b19ed68","repo":"apache/beam","slug":"list-of-serializablefunction-must-be-the-same-size-as-the","errorCode":null,"errorMessage":"List of SerializableFunction must be the same size as the PCollectionList","messagePattern":"List of SerializableFunction must be the same size as the PCollectionList","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java","lineNumber":622,"sourceCode":"      for (int i = 0; i < pCollectionList.size(); i++) {\n        PAssert.that(pCollectionList.get(i)).satisfies(checkerFn);\n      }\n      return this;\n    }\n\n    /**\n     * Takes list of {@link SerializableFunction}s of the same size as {@link #pCollectionList}, and\n     * applies each matcher to the {@code PCollection} with the identical index in the {@link\n     * #pCollectionList}.\n     *\n     * <p>Returns this {@code PCollectionListContentsAssert}.\n     */\n    public PCollectionListContentsAssert<T> satisfies(\n        List<SerializableFunction<Iterable<T>, Void>> checkerFnList) {\n      if (checkerFnList == null) {\n        throw new IllegalArgumentException(\"List of SerializableFunction must not be null\");\n      } else if (checkerFnList.size() != pCollectionList.size()) {\n        throw new IllegalArgumentException(\n            \"List of SerializableFunction must be the same size as the PCollectionList\");\n      }\n      for (int i = 0; i < pCollectionList.size(); i++) {\n        PAssert.that(pCollectionList.get(i)).satisfies(checkerFnList.get(i));\n      }\n      return this;\n    }\n  }\n\n  /**\n   * An {@link IterableAssert} about the contents of a {@link PCollection}. This does not require\n   * the runner to support side inputs.\n   */\n  protected static class PCollectionContentsAssert<T> implements IterableAssert<T> {\n    private final PCollection<T> actual;\n    private final AssertionWindows rewindowingStrategy;\n    private final SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor;\n    private final PAssertionSite site;","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java#L604-L640","documentation":"PAssert's PCollectionListContentsAssert.satisfies(List<SerializableFunction>) requires one checker function per PCollection in the list. When the list of checkers has a different size than the PCollectionList, it throws this IllegalArgumentException, because there would be no defined pairing between checkers and collections.","triggerScenarios":"Calling PAssert.that(pcollectionList).satisfies(checkers) where checkers.size() != pcollectionList.size() — e.g. building checkers for a subset of PCollections, or the PCollectionList gains an element while the checker list does not.","commonSituations":"Tests whose pipeline is modified to add another PCollection to the list but whose checker list wasn't updated; dynamically generated lists where counts drift.","solutions":["Provide exactly one SerializableFunction per PCollection in the PCollectionList, in order","Derive the checker list from the PCollectionList itself so sizes can't diverge","Assert each PCollection separately with PAssert.that(pcollection).satisfies(...) instead of the list variant"],"exampleFix":"// before\nassertThat(list).satisfies(Collections.singletonList(checker)); // list has 2 PCollections\n// after\nassertThat(list).satisfies(Arrays.asList(checker1, checker2));","handlingStrategy":"validation","validationCode":"if (checkerFnList.size() != pcollectionList.size()) {\n  throw new IllegalStateException(\"Need \" + pcollectionList.size() + \" checkers, got \" + checkerFnList.size());\n}","typeGuard":"boolean checkersMatchList(List<?> checkers, PCollectionList<?> list) {\n  return checkers != null && checkers.size() == list.size();\n}","tryCatchPattern":"try {\n  assertThat(pcollectionList).satisfies(checkers);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"same size as the PCollectionList\")) {\n    throw new IllegalStateException(\"Add/remove checkers to match PCollectionList size\", e);\n  }\n  throw e;\n}","preventionTips":["Generate the checker list from the same code that builds the PCollectionList so sizes stay in sync","Update checker lists whenever the pipeline adds PCollections to the list","Prefer per-PCollection PAssert.that(...).satisfies(...) for lists that change shape"],"tags":["apache-beam","passert","argument-validation","testing"],"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-20T03:17:13.778Z"}