diff --git a/rewrite-java/src/main/java/org/openrewrite/java/LombokUtilityClass.java b/rewrite-java/src/main/java/org/openrewrite/java/LombokUtilityClass.java index 09f847de122..5d0e7d428e1 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/LombokUtilityClass.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/LombokUtilityClass.java @@ -137,6 +137,10 @@ public J.MethodDeclaration visitMethodDeclaration( if (!method.hasModifier(J.Modifier.Type.Static)) { shouldPerformChanges.set(false); } + + if (method.getSimpleName().equalsIgnoreCase("main")) { + shouldPerformChanges.set(false); + } return super.visitMethodDeclaration(method, shouldPerformChanges); } diff --git a/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java b/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java index e89957e29f6..ca27cee88e8 100644 --- a/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java +++ b/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java @@ -14,7 +14,6 @@ * - abstract classes * - instantiations of changed classes * - constructor - * - public static void main */ class LombokUtilityClassTest implements RewriteTest { @@ -237,6 +236,21 @@ public int add(final int x, final int y) { ); } + @Test + void givenMain() { + rewriteRun( + recipeSpec -> recipeSpec.recipe(new LombokUtilityClass()), + java( + """ + public class A { + public static void main(String[] args) { + } + } + """ + ) + ); + } + } @Test