From 105bdab4e0d4775eff2a070f961f666c3d75b89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Schn=C3=A9ider?= Date: Fri, 19 Jul 2024 09:19:43 -0600 Subject: [PATCH] Avoid potential for StackOverflow on J#getWeight (#4343) --- .../src/main/java/org/openrewrite/java/tree/J.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java index 4aea20dc7b5..1047f0b84eb 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java @@ -1528,11 +1528,9 @@ public JavaType visit(@Nullable JavaType javaType, AtomicInteger n) { }; @Override - public @Nullable J visit(@Nullable Tree tree, AtomicInteger n) { - if (tree != null) { - n.incrementAndGet(); - } - return super.visit(tree, n); + public @Nullable J preVisit(J tree, AtomicInteger n) { + n.incrementAndGet(); + return tree; } @Override