openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
1.98k stars 292 forks source link

Recognize recipes containing themself #4209

Open Bananeweizen opened 1 month ago

Bananeweizen commented 1 month ago

What problem are you trying to solve?

I accidentally included a recipe in itself. The StackoverflowError should be avoided, and a clear error message should be presented.

Describe the solution you'd like

Check any nested recipe to not be in the "already seen" set at the beginning of the initialization request.

Additional context

---
type: specs.openrewrite.org/v1beta/recipe
name: myrecipes
displayName: My recipes
description: Accidentially contains itself
recipeList:
  - myrecipes
java.lang.StackOverflowError
    at org.openrewrite.config.DeclarativeRecipe.initialize (DeclarativeRecipe.java:96)
    at org.openrewrite.config.DeclarativeRecipe.initialize (DeclarativeRecipe.java:91)
    at org.openrewrite.config.DeclarativeRecipe.initialize (DeclarativeRecipe.java:106)
    at org.openrewrite.config.DeclarativeRecipe.initialize (DeclarativeRecipe.java:91)

Are you interested in contributing this feature to OpenRewrite?

Yes.

timtebeek commented 1 month ago

Hah, not the first time seeing that indeed; would be good to have that handled explicitly; thanks for offering to help!