From 04059cea573513ade681cf4946bf8bf0069cf0b2 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 24 Jan 2025 13:38:56 +0100 Subject: [PATCH] Allow `io.moderne` recipes to mutate the execution context --- .../CursorValidatingExecutionContextView.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/rewrite-core/src/main/java/org/openrewrite/CursorValidatingExecutionContextView.java b/rewrite-core/src/main/java/org/openrewrite/CursorValidatingExecutionContextView.java index cb8be5ce807..779649f9751 100644 --- a/rewrite-core/src/main/java/org/openrewrite/CursorValidatingExecutionContextView.java +++ b/rewrite-core/src/main/java/org/openrewrite/CursorValidatingExecutionContextView.java @@ -49,15 +49,19 @@ public CursorValidatingExecutionContextView setValidateImmutableExecutionContext @Override public void putMessage(String key, @Nullable Object value) { - boolean mutationAllowed = !getMessage(VALIDATE_CTX_MUTATION, false) || key.equals(VALIDATE_CURSOR_ACYCLIC) || key.equals(VALIDATE_CTX_MUTATION) - || key.equals(ExecutionContext.CURRENT_CYCLE) || key.equals(ExecutionContext.CURRENT_RECIPE) || key.equals(ExecutionContext.DATA_TABLES) - || key.startsWith("org.openrewrite.maven"); // MavenExecutionContextView stores metrics - assert mutationAllowed - : "Recipe mutated execution context key \"" + key + "\". " + - "Recipes should not mutate the contents of the ExecutionContext as it allows mutable state to leak between " + - "recipes, opening the door for difficult to debug recipe composition errors. " + - "If you need to store state within the execution of a single recipe use Cursor messaging. " + - "If you want to pass state between recipes, use a ScanningRecipe instead."; + boolean mutationAllowed = !getMessage(VALIDATE_CTX_MUTATION, false) + || key.equals(VALIDATE_CURSOR_ACYCLIC) + || key.equals(VALIDATE_CTX_MUTATION) + || key.equals(ExecutionContext.CURRENT_CYCLE) + || key.equals(ExecutionContext.CURRENT_RECIPE) + || key.equals(ExecutionContext.DATA_TABLES) + || key.startsWith("org.openrewrite.maven") // MavenExecutionContextView stores metrics + || key.startsWith("io.moderne"); // We ought to know what we're doing + assert mutationAllowed : "Recipe mutated execution context key \"" + key + "\". " + + "Recipes should not mutate the contents of the ExecutionContext as it allows mutable state to leak between " + + "recipes, opening the door for difficult to debug recipe composition errors. " + + "If you need to store state within the execution of a single recipe use Cursor messaging. " + + "If you want to pass state between recipes, use a ScanningRecipe instead."; super.putMessage(key, value); } }