{"record":{"id":"68b4e0e344e43e11","repo":"apache/beam","slug":"tests-for-java-equality-of-the-s-object-not-the-pcollection","errorCode":null,"errorMessage":"tests for Java equality of the %s object, not the PCollection in question. Call a test method, such as isEqualTo.","messagePattern":"tests for Java equality of the (.+?) object, not the PCollection in question\\. Call a test method, such as isEqualTo\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java","lineNumber":1062,"sourceCode":"     * assert and the provided expected value.\n     *\n     * <p>Returns this {@code SingletonAssert}.\n     */\n    private PCollectionSingletonAssert<T> satisfies(\n        AssertRelation<T, T> relation, final T expected) {\n      return satisfies(new CheckRelationAgainstExpected<>(relation, expected, coder));\n    }\n\n    /**\n     * @throws UnsupportedOperationException always\n     * @deprecated {@link Object#equals(Object)} is not supported on PAssert objects. If you meant\n     *     to test PCollection equality, use {@link #isEqualTo} instead.\n     */\n    @SuppressFBWarnings(\"EQ_UNUSUAL\")\n    @Deprecated\n    @Override\n    public boolean equals(@Nullable Object o) {\n      throw new UnsupportedOperationException(\n          String.format(\n              \"tests for Java equality of the %s object, not the PCollection in question. \"\n                  + \"Call a test method, such as isEqualTo.\",\n              getClass().getSimpleName()));\n    }\n\n    /**\n     * @throws UnsupportedOperationException always.\n     * @deprecated {@link Object#hashCode()} is not supported on {@link PAssert} objects.\n     */\n    @Deprecated\n    @Override\n    public int hashCode() {\n      throw new UnsupportedOperationException(\n          String.format(\"%s.hashCode() is not supported.\", SingletonAssert.class.getSimpleName()));\n    }\n  }\n","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java#L1044-L1080","documentation":"PAssert's top-level assertion classes intentionally break Object.equals to enforce that users test PCollection contents rather than assert-object identity: calling equals() always throws UnsupportedOperationException. The message tells the user the call only tested Java equality of the assert object, not the PCollection, and to use assertion methods like isEqualTo instead.","triggerScenarios":"Calling equals() on a PAssert assertion object — via assertEquals(assertObj, x), assertThat(...).isEqualTo(assertObj), list/set membership checks (contains/isIn), or non-Beam assertion frameworks resolving to equals on PAssert objects.","commonSituations":"Porting JUnit assertEquals-style tests to PAssert; comparing two PAssert objects from different pipelines; framework code (e.g. assertThat(x).isIn(collection)) invoking equals under the hood.","solutions":["Use isEqualTo(...) on the PAssert to compare the PCollection to an expected value","Use containsInAnyOrder / satisfies(...) for content checks","Never pass PAssert assertion objects to equals-based comparison APIs"],"exampleFix":"// before\nassertEquals(pAssertObject, expected);\n// after\nPAssert.that(pcollection).isEqualTo(expected);","handlingStrategy":"validation","validationCode":"if (obj instanceof org.apache.beam.sdk.testing.PAssert) {\n  throw new IllegalStateException(\"Call isEqualTo/containsInAnyOrder on the PAssert instead of equals()\");\n}","typeGuard":"boolean isPAssertType(Object o) {\n  return o.getClass().getName().startsWith(\"org.apache.beam.sdk.testing.PAssert$\");\n}","tryCatchPattern":"try {\n  assertTrue(pAssertObject.equals(other));\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"isEqualTo\")) {\n    // replace with PAssert.that(pcollection).isEqualTo(expected)\n  }\n}","preventionTips":["Replace assertEquals/assertJ isEqualTo calls involving PAssert objects with PAssert's own isEqualTo(...)","Never use PAssert objects inside contains/isIn or collections that call equals","Treat PAssert instances as one-shot assertion builders, not comparable values"],"tags":["apache-beam","passert","equals-contract","testing"],"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"}