apache/beam · error · UnsupportedOperationException

tests for Java equality of the

Error message

tests for Java equality of the %s object, not the PCollection in question. Call a test method, such as isEqualTo.

What it means

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.

Solutions

  1. Use isEqualTo(...) on the PAssert to compare the PCollection to an expected value
  2. Use containsInAnyOrder / satisfies(...) for content checks
  3. Never pass PAssert assertion objects to equals-based comparison APIs

Example fix

// before
assertEquals(pAssertObject, expected);
// after
PAssert.that(pcollection).isEqualTo(expected);
Defensive patterns

Strategy: validation

Validate before calling

if (obj instanceof org.apache.beam.sdk.testing.PAssert) {
  throw new IllegalStateException("Call isEqualTo/containsInAnyOrder on the PAssert instead of equals()");
}

Type guard

boolean isPAssertType(Object o) {
  return o.getClass().getName().startsWith("org.apache.beam.sdk.testing.PAssert$");
}

Try / catch

try {
  assertTrue(pAssertObject.equals(other));
} catch (UnsupportedOperationException e) {
  if (e.getMessage().contains("isEqualTo")) {
    // replace with PAssert.that(pcollection).isEqualTo(expected)
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/68b4e0e344e43e11. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java:1062

     * assert and the provided expected value.
     *
     * <p>Returns this {@code SingletonAssert}.
     */
    private PCollectionSingletonAssert<T> satisfies(
        AssertRelation<T, T> relation, final T expected) {
      return satisfies(new CheckRelationAgainstExpected<>(relation, expected, coder));
    }

    /**
     * @throws UnsupportedOperationException always
     * @deprecated {@link Object#equals(Object)} is not supported on PAssert objects. If you meant
     *     to test PCollection equality, use {@link #isEqualTo} instead.
     */
    @SuppressFBWarnings("EQ_UNUSUAL")
    @Deprecated
    @Override
    public boolean equals(@Nullable Object o) {
      throw new UnsupportedOperationException(
          String.format(
              "tests for Java equality of the %s object, not the PCollection in question. "
                  + "Call a test method, such as isEqualTo.",
              getClass().getSimpleName()));
    }

    /**
     * @throws UnsupportedOperationException always.
     * @deprecated {@link Object#hashCode()} is not supported on {@link PAssert} objects.
     */
    @Deprecated
    @Override
    public int hashCode() {
      throw new UnsupportedOperationException(
          String.format("%s.hashCode() is not supported.", SingletonAssert.class.getSimpleName()));
    }
  }

View on GitHub (pinned to 12126d8942)