Skip to content

Make SinkEventAttributeSet.hashCode ignore resolveParent (#1075) - #1091

Merged
slachiewicz merged 1 commit into
apache:masterfrom
tanvir-ux:fix-1075-hashcode-ignore-parent
Sep 3, 2026
Merged

slachiewicz merged 1 commit into
apache:masterfrom
tanvir-ux:fix-1075-hashcode-ignore-parent

Conversation

@tanvir-ux

Copy link
Copy Markdown
Contributor

SinkEventAttributeSet.equals() already delegates to isEqual(), which compares only own attributes. hashCode() was adding the resolve parent, so two equal sets could have different hash codes.

I dropped the parent from hashCode() so it matches existing equality. getAttribute() still walks the parent. This is the least disruptive option from #1075. I did not change equals semantics.

checkHashCode now expects setResolveParent not to change the hash. I also added a contract test for two sets with the same own attributes and different parents.

This is independent of #1073 (the class move). Happy to rebase if that lands first.

Fixes #1075

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

I ran mvn -pl doxia-core -am test -Dtest=SinkEventAttributeSetTest -Dsurefire.failIfNoSpecifiedTests=false locally (18 tests, green, including checkstyle/spotless/rat on those modules). I did not run -Prun-its.

@slachiewicz

Copy link
Copy Markdown
Member

#1073 landed as e83c5a2 and moved both files this PR touches, so it now conflicts.

The code is unchanged, only relocated:

  • doxia-sink-api/src/main/java/org/apache/maven/doxia/sink/SinkEventAttributeSet.java —
    hashCode() is at line 358, still adding parentHash
  • doxia-sink-api/src/test/java/org/apache/maven/doxia/sink/SinkEventAttributeSetTest.java

doxia-core keeps a deprecated subclass that declares neither equals nor hashCode, so
the fix still applies once, in the new location. SinkEventAttributeSetCompatibilityTest
in doxia-core pins unrelated behaviour and needs no change.

The move was in flight when you opened this — apologies for the churn.

This comment was created with AI assistance.

@tanvir-ux
tanvir-ux force-pushed the fix-1075-hashcode-ignore-parent branch from 17ad8ce to 91bafc8 Compare September 3, 2026 13:47
@tanvir-ux

Copy link
Copy Markdown
Contributor Author

Rebased onto master after #1073. Same hashCode change, now in doxia-sink-api.

equals() already follows isEqual() and compares only own attributes. hashCode was folding in the resolve parent, so two equal sets could have different hash codes.

Rebased onto master after apache#1073 moved these files into doxia-sink-api.

Fixes apache#1075
@slachiewicz
slachiewicz force-pushed the fix-1075-hashcode-ignore-parent branch from 91bafc8 to 8e33ffc Compare September 3, 2026 14:53
@slachiewicz slachiewicz added the bug Something isn't working label Sep 3, 2026
@slachiewicz
slachiewicz merged commit 7ebd409 into apache:master Sep 3, 2026
11 checks passed
@github-actions github-actions Bot added this to the 2.2.0 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SinkEventAttributeSet.equals and hashCode disagree about resolveParent

2 participants