Initialize ScanningRecipe accumulator key eagerly for thread safety#6914
Merged
pstreef merged 1 commit intoopenrewrite:mainfrom Mar 16, 2026
Merged
Conversation
The recipeAccMessage field used lazy initialization that was not thread-safe. If two concurrent recipe runs accessed the same shared ScanningRecipe instance before initialization, both threads could generate different UUIDs, causing one thread's accumulator data to be stored under a key that gets overwritten. Change to eager initialization at field declaration, which is inherently thread-safe since the JVM guarantees constructor completion before the object is visible to other threads.
601bcea to
9a2690b
Compare
timtebeek
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ScanningRecipe.recipeAccMessageuses lazy initialization that is not thread-safe:When recipe instances are shared across concurrent runs, two threads can see
nullsimultaneously, generate different UUIDs, and one overwrites the other. The losing thread's accumulator data — stored under the now-orphaned UUID — becomes unreachable.Solution
Change to eager initialization at field declaration. The UUID generation cost is negligible and the field is always used, so lazy init provided no benefit. The
clone()method continues to assign a new UUID as before.