diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java b/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java index b4d480f4d09..8ab0b990d3e 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java @@ -676,7 +676,8 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, At } public static JavaType.FullyQualified getTopLevelClassName(JavaType.FullyQualified classType) { - if (classType.getOwningClass() == null) { + if (classType.getOwningClass() == null || TypeUtils.fullyQualifiedNamesAreEqual(classType.getFullyQualifiedName(), + classType.getOwningClass().getFullyQualifiedName())) { return classType; } return getTopLevelClassName(classType.getOwningClass());