Skip to content

Commit 93bfd38

Browse files
committed
Avoid IllegalStateException in AddConfigurationAnnotationIfBeansPresent
1 parent 761d462 commit 93bfd38

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/main/java/org/openrewrite/java/spring/boot2/AddConfigurationAnnotationIfBeansPresent.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package org.openrewrite.java.spring.boot2;
1717

18-
import org.openrewrite.Cursor;
19-
import org.openrewrite.ExecutionContext;
20-
import org.openrewrite.Recipe;
21-
import org.openrewrite.TreeVisitor;
18+
import org.openrewrite.*;
2219
import org.openrewrite.java.AnnotationMatcher;
2320
import org.openrewrite.java.JavaIsoVisitor;
2421
import org.openrewrite.java.JavaParser;
@@ -97,8 +94,8 @@ public static boolean isApplicableClass(J.ClassDeclaration classDecl, Cursor cur
9794

9895
if (!isStatic) {
9996
// no static keyword? check if it is top level class in the CU
100-
J.CompilationUnit cu = cursor.dropParentUntil(J.CompilationUnit.class::isInstance).getValue();
101-
if (!cu.getClasses().contains(classDecl)) {
97+
Object enclosing = cursor.dropParentUntil(it -> it instanceof J.ClassDeclaration || it == Cursor.ROOT_VALUE).getValue();
98+
if (enclosing instanceof J.ClassDeclaration) {
10299
return false;
103100
}
104101
}

0 commit comments

Comments
 (0)