From de629544a37242d300a14d7d7d7e7f7e1715b09e Mon Sep 17 00:00:00 2001 From: Skylot <118523+skylot@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:04:07 +0000 Subject: [PATCH] fix: force type var short form as a key in generic resolve mapping (#2370) --- .../jadx/core/dex/nodes/utils/TypeUtils.java | 4 ++ .../integration/types/TestGenerics8.java | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics8.java diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java b/jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java index d992aee262a..8259df38b61 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java @@ -226,6 +226,10 @@ public Map getTypeVariablesMapping(ArgType clsType) { for (int i = 0; i < genericParamsCount; i++) { ArgType actualType = actualTypes.get(i); ArgType typeVar = typeParameters.get(i); + if (typeVar.getExtendTypes() != null) { + // force short form (only type var name) + typeVar = ArgType.genericType(typeVar.getObject()); + } replaceMap.put(typeVar, actualType); } return replaceMap; diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics8.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics8.java new file mode 100644 index 00000000000..9280422a562 --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics8.java @@ -0,0 +1,47 @@ +package jadx.tests.integration.types; + +import org.junit.jupiter.api.Test; + +import jadx.tests.api.IntegrationTest; + +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + +public class TestGenerics8 extends IntegrationTest { + + public static class TestCls { + + public abstract static class Class2 extends Parent2 { + public void test() { + S s = get(); + s.i1(); + s.i2(); + } + } + + static class Parent2 { + T t; + + protected T get() { + return t; + } + } + + interface I1 { + void i1(); + } + + interface I2 { + void i2(); + } + } + + @Test + public void test() { + noDebugInfo(); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("S s = get();") + .containsOne("s.i1();") + .containsOne("s.i2();"); + } +}