Skip to content

Commit c22f89b

Browse files
authored
Initialize ScanningRecipe accumulator key eagerly (#6914)
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.
1 parent 4e23b2e commit c22f89b

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/ScanningRecipe.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@
3535
*/
3636
@SuppressWarnings("ALL")
3737
public abstract class ScanningRecipe<T> extends Recipe {
38-
@Nullable
39-
private String recipeAccMessage;
38+
private String recipeAccMessage = "org.openrewrite.recipe.acc." + UUID.randomUUID();
4039

41-
private String getRecipeAccMessage() {
42-
if (recipeAccMessage == null) {
43-
recipeAccMessage = "org.openrewrite.recipe.acc." + UUID.randomUUID();
44-
}
40+
String getRecipeAccMessage() {
4541
return recipeAccMessage;
4642
}
4743

0 commit comments

Comments
 (0)