apache/beam · error · UnsupportedOperationException
.hashCode() is not supported.
Error message
%s.hashCode() is not supported.
What it means
PAssert's PCollectionContentsAssert (IterableAssert) intentionally breaks Object.hashCode: calling hashCode() always throws UnsupportedOperationException. Combined with the broken equals(), this prevents PAssert objects from being used in hash-based collections, which would be meaningless for an assertion object.
Solutions
- Don't store PAssert assertion objects in hash-based collections; run each assertion directly
- Keep references in a List and iterate to invoke the assertion methods
- If identity grouping is needed, wrap in your own holder class with a valid hashCode/equals
Example fix
// before Set<IterableAssert<?>> asserts = new HashSet<>(); asserts.add(assertThat(pcollection)); // after List<IterableAssert<?>> asserts = new ArrayList<>(); asserts.add(assertThat(pcollection));
Defensive patterns
Strategy: validation
Validate before calling
if (obj instanceof org.apache.beam.sdk.testing.PAssert.IterableAssert) {
throw new IllegalStateException("PAssert objects cannot be hashed or used as map keys");
} Type guard
boolean isHashable(Object o) {
return !(o instanceof org.apache.beam.sdk.testing.PAssert.IterableAssert);
} Try / catch
try {
Set<Object> set = new HashSet<>(assertObjects);
} catch (UnsupportedOperationException e) {
if (e.getMessage().contains("hashCode() is not supported")) {
// switch to a List or wrap in a holder with valid hashCode
}
} Prevention
- Store PAssert objects in Lists, never Sets/HashMaps
- Invoke PAssert assertions immediately rather than collecting them for later
- Note that equals() is also unsupported on PAssert objects — avoid any identity-based API
When it happens
Trigger: Using a PAssert assertion object as a HashMap key, in a HashSet, with Collectors.toMap/groupingBy, or any hashing utility (e.g. Objects.hash(assertObj), Guava Hashing) on the assert object.
Common situations: Collecting multiple PAssert objects into a Set for batch evaluation; passing assert objects into hashing-based test utilities; accidentally logging with a framework that hashes objects.
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
- If you meant to test object equality, use…
- List of SerializableFunction must be the same size as the…
- List of SerializableFunction must not be null
- tests for Java equality of the
- assert_that must be used within a beam.Pipeline context…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/0bd65b7ecc731b1d.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java:814
* @deprecated {@link Object#equals(Object)} is not supported on PAssert objects. If you meant
* to test object equality, use a variant of {@link #containsInAnyOrder} instead.
*/
@Deprecated
@Override
@SuppressFBWarnings("EQ_UNUSUAL")
public boolean equals(@Nullable Object o) {
throw new UnsupportedOperationException(
"If you meant to test object equality, use .containsInAnyOrder instead.");
}
/**
* @throws UnsupportedOperationException always.
* @deprecated {@link Object#hashCode()} is not supported on PAssert objects.
*/
@Deprecated
@Override
public int hashCode() {
throw new UnsupportedOperationException(
String.format("%s.hashCode() is not supported.", IterableAssert.class.getSimpleName()));
}
}
/**
* An {@link IterableAssert} for an iterable that is the sole element of a {@link PCollection}.
* This does not require the runner to support side inputs.
*/
private static class PCollectionSingletonIterableAssert<T> implements IterableAssert<T> {
private final PCollection<Iterable<T>> actual;
private final Coder<T> elementCoder;
private final AssertionWindows rewindowingStrategy;
private final SimpleFunction<Iterable<ValueInSingleWindow<Iterable<T>>>, Iterable<Iterable<T>>>
paneExtractor;
private final PAssertionSite site;
public PCollectionSingletonIterableAssert(
PCollection<Iterable<T>> actual, PAssertionSite site) {View on GitHub (pinned to 12126d8942)