Skip to content

fix: include all operands in AbstractLogicalMatcher equals/hashCode#3400

Merged
tomakehurst merged 2 commits into
wiremock:masterfrom
rnagulapalle:fix/logical-matcher-equals-all-operands
Apr 30, 2026
Merged

fix: include all operands in AbstractLogicalMatcher equals/hashCode#3400
tomakehurst merged 2 commits into
wiremock:masterfrom
rnagulapalle:fix/logical-matcher-equals-all-operands

Conversation

@rnagulapalle

Copy link
Copy Markdown
Contributor

What

Overrides equals() and hashCode() in AbstractLogicalMatcher to compare the full operands list, not just the inherited expectedValue.

Why

AbstractLogicalMatcher inherits equals()/hashCode() from StringValuePattern, which only compares the expectedValue field. The constructor passes only the first operand's expected value to the parent via checkAtLeast2OperandsAndReturnFirstExpected().

This means two LogicalAnd/LogicalOr instances with the same first operand but different subsequent operands are incorrectly treated as equal:

LogicalAnd matcher1 = new LogicalAnd(WireMock.equalTo("A"), WireMock.equalTo("B"));
LogicalAnd matcher2 = new LogicalAnd(WireMock.equalTo("A"), WireMock.equalTo("C"));

matcher1.equals(matcher2); // true — should be false

This causes incorrect stub deduplication when ignoreRepeatRequests is used with a StubMappingTransformer that produces logical AND/OR body patterns.

Changes

  • AbstractLogicalMatcher.java — override equals() to also compare operands list; override hashCode() to include operands
  • LogicalAndTest.java — added test: same first operand, different later operands → not equal
  • LogicalOrTest.java — added same test for LogicalOr

Fixes #3353

Made with Cursor

AbstractLogicalMatcher inherits equals()/hashCode() from
StringValuePattern, which only compares the expectedValue field.
Since the constructor passes only the first operand's expected value
to the parent, two LogicalAnd/LogicalOr instances with the same first
operand but different subsequent operands are incorrectly treated as
equal.

Override equals() and hashCode() to also compare the full operands
list, so matchers with different operand sets are correctly
distinguished.

This fixes incorrect stub deduplication when ignoreRepeatRequests is
used with a StubMappingTransformer that produces logical AND/OR body
patterns.

Fixes wiremock#3353

Made-with: Cursor
@rnagulapalle rnagulapalle requested a review from a team as a code owner April 28, 2026 22:01
@tomakehurst

Copy link
Copy Markdown
Member

Please can you run ./gradlew :spotlessApply and push

@sivakumarbuddha

Copy link
Copy Markdown

@rnagulapalle can you take a look at the above review comments

@sivakumarbuddha

Copy link
Copy Markdown

@tomakehurst please review.

@tomakehurst tomakehurst merged commit eebc537 into wiremock:master Apr 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WireMock Java library: AbstractLogicalMatcher equality check is not considering all operands

3 participants