Skip to content

Fix thread-safety of several recipes - #1284

Merged
greg-at-moderne merged 2 commits into
mainfrom
greg-static-precondition-visitors
Nov 4, 2026
Merged

greg-at-moderne merged 2 commits into
mainfrom
greg-static-precondition-visitors

Conversation

@greg-at-moderne

@greg-at-moderne greg-at-moderne commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What's changed?

AssertionsArgumentOrder now creates its UsesMethod precondition visitors inside each getVisitor() call. Before, it kept them in a static field that every thread shared.

Also the same change in AddMissingNested and LifecycleNonPrivate, but only as a precaution. In practice UsesType is thread-safe, but not guaranteed to be.

What's your motivation?

OpenRewriteRecipeBestPractices fails on random test files in nightly Moderne runs, with 1–12 files a night across several repos. UsesMethod keeps a cursor, and when files run in parallel one thread resets that cursor while another is still using it:

java.lang.NullPointerException: Cannot invoke "org.openrewrite.Cursor.getMessage(String, Object)" because "this.cursor" is null
  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:237)
  org.openrewrite.Preconditions$Or.visit(Preconditions.java:120)
  org.openrewrite.Preconditions$Or.visit(Preconditions.java:103)
  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:147)
  org.openrewrite.Preconditions$Check.visit(Preconditions.java:184)
  org.openrewrite.Preconditions$Check.visit(Preconditions.java:156)
  org.openrewrite.scheduling.RecipeRunCycle.lambda$editSource$10(RecipeRunCycle.java:538)

… suppressions and stop test workers on interrupt
@greg-at-moderne
greg-at-moderne marked this pull request as ready for review November 4, 2026 14:26
@greg-at-moderne
greg-at-moderne merged commit 847db20 into main Nov 4, 2026
1 check passed
@greg-at-moderne
greg-at-moderne deleted the greg-static-precondition-visitors branch November 4, 2026 14:26
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant