Skip to content

Converge AssertJ isSameAs/isNotSameAs(0|1) within a single run#1036

Merged
timtebeek merged 1 commit into
mainfrom
tim/assertj-issamezero-converge
Jun 20, 2026
Merged

Converge AssertJ isSameAs/isNotSameAs(0|1) within a single run#1036
timtebeek merged 1 commit into
mainfrom
tim/assertj-issamezero-converge

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 20, 2026

Copy link
Copy Markdown
Member

What's changed?

Root cause

Within the aggregate, Picnic's AssertJPrimitiveRulesRecipes normalizes isSameAs/isNotSameAs on primitives to isEqualTo/isNotEqualTo. Our type-specific rules then collapse isEqualTo(0)isZero(), etc. But the node produced by the primitive rule isn't given a typed (AbstractIntegerAssert) receiver by between-cycle re-attribution, so our Refaster rules don't match it until the source is fully re-parsed on a later run.

Fix

  • Our overriding number rules (Integer, Long, Short, Byte, Double, Float) now also match the isSameAs/isNotSameAs forms directly, collapsing straight to isZero()/isNotZero()/isOne() on the freshly-parsed, fully-typed source.
  • Reordered AssertJShortRulesRecipes ahead of AssertJPrimitiveRulesRecipes so all our number rules run before the primitive normalization (the other six already did), letting them win within a single cycle.

BigInteger is unaffected — Picnic's primitive rules don't touch it, so there is no intermediate isSameAsisEqualTo step to converge.

Testing

…in a single run

The Assertj aggregate normalizes primitive isSameAs/isNotSameAs to
isEqualTo/isNotEqualTo via Picnic's AssertJPrimitiveRulesRecipes, after
which our type-specific rules collapse isEqualTo(0) to isZero(), etc.
Because between-cycle re-attribution does not give the rewritten node a
typed receiver, the second simplification only fired on a subsequent
rewriteRun.

Let our type rules also match the isSameAs/isNotSameAs forms directly so
they collapse straight to isZero/isNotZero/isOne, and order them before
AssertJPrimitiveRulesRecipes so they win within a single cycle.

Fixes #1032
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 20, 2026
@timtebeek timtebeek merged commit cd8b263 into main Jun 20, 2026
1 check passed
@timtebeek timtebeek deleted the tim/assertj-issamezero-converge branch June 20, 2026 12:21
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

AssertJ aggregate is not idempotent: isNotSameAs(0) → isNotEqualTo(0) → isNotZero() requires two rewriteRuns

1 participant