From e4fc6774b1747d63ff29d98bbc79da0c6873ef7c Mon Sep 17 00:00:00 2001 From: Skylot Date: Wed, 10 Jul 2019 16:58:52 +0300 Subject: [PATCH] fix: make correct hash calculation for GenericObject type (#705) --- .../jadx/core/dex/instructions/args/ArgType.java | 11 +++++++---- .../core/dex/instructions/args/ArgTypeTest.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java index 28da64260..fc4f8704d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java @@ -156,7 +156,7 @@ public abstract class ArgType { } private static class ObjectType extends KnownType { - private final String objName; + protected final String objName; public ObjectType(String obj) { this.objName = Utils.cleanObjectName(obj); @@ -269,15 +269,18 @@ public abstract class ArgType { super(obj); this.outerType = null; this.generics = generics; - this.hash = obj.hashCode() + 31 * Arrays.hashCode(generics); + this.hash = calcHash(); } public GenericObject(GenericObject outerType, String innerName, ArgType[] generics) { super(outerType.getObject() + '$' + innerName); this.outerType = outerType; this.generics = generics; - this.hash = outerType.hashCode() + 31 * innerName.hashCode() - + 31 * 31 * Arrays.hashCode(generics); + this.hash = calcHash(); + } + + private int calcHash() { + return objName.hashCode() + 31 * Arrays.hashCode(generics); } @Override diff --git a/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java b/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java new file mode 100644 index 000000000..35f34fa3a --- /dev/null +++ b/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java @@ -0,0 +1,16 @@ +package jadx.core.dex.instructions.args; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class ArgTypeTest { + + @Test + void testEqualsOfGenericTypes() { + ArgType first = ArgType.generic("java.lang.List", ArgType.STRING); + ArgType second = ArgType.generic("Ljava/lang/List;", ArgType.STRING); + + assertEquals(first, second); + } +}