{"record":{"id":"0bd65b7ecc731b1d","repo":"apache/beam","slug":"s-hashcode-is-not-supported","errorCode":null,"errorMessage":"%s.hashCode() is not supported.","messagePattern":"(.+?)\\.hashCode\\(\\) is not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java","lineNumber":814,"sourceCode":"     * @deprecated {@link Object#equals(Object)} is not supported on PAssert objects. If you meant\n     *     to test object equality, use a variant of {@link #containsInAnyOrder} instead.\n     */\n    @Deprecated\n    @Override\n    @SuppressFBWarnings(\"EQ_UNUSUAL\")\n    public boolean equals(@Nullable Object o) {\n      throw new UnsupportedOperationException(\n          \"If you meant to test object equality, use .containsInAnyOrder instead.\");\n    }\n\n    /**\n     * @throws UnsupportedOperationException always.\n     * @deprecated {@link Object#hashCode()} is not supported on PAssert objects.\n     */\n    @Deprecated\n    @Override\n    public int hashCode() {\n      throw new UnsupportedOperationException(\n          String.format(\"%s.hashCode() is not supported.\", IterableAssert.class.getSimpleName()));\n    }\n  }\n\n  /**\n   * An {@link IterableAssert} for an iterable that is the sole element of a {@link PCollection}.\n   * This does not require the runner to support side inputs.\n   */\n  private static class PCollectionSingletonIterableAssert<T> implements IterableAssert<T> {\n    private final PCollection<Iterable<T>> actual;\n    private final Coder<T> elementCoder;\n    private final AssertionWindows rewindowingStrategy;\n    private final SimpleFunction<Iterable<ValueInSingleWindow<Iterable<T>>>, Iterable<Iterable<T>>>\n        paneExtractor;\n    private final PAssertionSite site;\n\n    public PCollectionSingletonIterableAssert(\n        PCollection<Iterable<T>> actual, PAssertionSite site) {","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java#L796-L832","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nSet<IterableAssert<?>> asserts = new HashSet<>();\nasserts.add(assertThat(pcollection));\n// after\nList<IterableAssert<?>> asserts = new ArrayList<>();\nasserts.add(assertThat(pcollection));","handlingStrategy":"validation","validationCode":"if (obj instanceof org.apache.beam.sdk.testing.PAssert.IterableAssert) {\n  throw new IllegalStateException(\"PAssert objects cannot be hashed or used as map keys\");\n}","typeGuard":"boolean isHashable(Object o) {\n  return !(o instanceof org.apache.beam.sdk.testing.PAssert.IterableAssert);\n}","tryCatchPattern":"try {\n  Set<Object> set = new HashSet<>(assertObjects);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"hashCode() is not supported\")) {\n    // switch to a List or wrap in a holder with valid hashCode\n  }\n}","preventionTips":["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"],"tags":["apache-beam","passert","hashcode-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"}