diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java b/jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
index 28dc135e5fd..493e2467875 100644
--- a/jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+++ b/jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
@@ -86,8 +86,11 @@ private static void removeSyntheticFields(ClassNode cls) {
 					ClassInfo clsInfo = ClassInfo.fromType(cls.root(), fldType);
 					ClassNode fieldsCls = cls.root().resolveClass(clsInfo);
 					ClassInfo parentClass = cls.getClassInfo().getParentClass();
-					if (fieldsCls != null
-							&& (inline || Objects.equals(parentClass, fieldsCls.getClassInfo()))) {
+					if (fieldsCls == null) {
+						continue;
+					}
+					boolean isParentInst = Objects.equals(parentClass, fieldsCls.getClassInfo());
+					if (inline || isParentInst) {
 						int found = 0;
 						for (MethodNode mth : cls.getMethods()) {
 							if (removeFieldUsageFromConstructor(mth, field, fieldsCls)) {
@@ -95,7 +98,9 @@ private static void removeSyntheticFields(ClassNode cls) {
 							}
 						}
 						if (found != 0) {
-							field.addAttr(new FieldReplaceAttr(fieldsCls.getClassInfo()));
+							if (isParentInst) {
+								field.addAttr(new FieldReplaceAttr(fieldsCls.getClassInfo()));
+							}
 							field.add(AFlag.DONT_GENERATE);
 						}
 					}
diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass22.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass22.java
new file mode 100644
index 00000000000..742a43b8393
--- /dev/null
+++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass22.java
@@ -0,0 +1,40 @@
+package jadx.tests.integration.inner;
+
+import org.junit.jupiter.api.Test;
+
+import jadx.tests.api.IntegrationTest;
+
+import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
+
+public class TestAnonymousClass22 extends IntegrationTest {
+
+	public static class TestCls {
+
+		public static class Parent {
+			public static Parent test(Class<?> cls) {
+				final AnotherClass another = new AnotherClass();
+				return new Parent() {
+					@Override
+					public String func() {
+						return another.toString();
+					}
+				};
+			}
+
+			public String func() {
+				return "";
+			}
+		}
+
+		public static class AnotherClass {
+		}
+	}
+
+	@Test
+	public void test() {
+		assertThat(getClassNode(TestCls.class))
+				.code()
+				.containsOne("return another.toString();")
+				.doesNotContain("AnotherClass.this");
+	}
+}