fix: make correct hash calculation for GenericObject type (#705)

This commit is contained in:
Skylot
2019-07-10 16:58:52 +03:00
parent f57dfb3f2e
commit e4fc6774b1
2 changed files with 23 additions and 4 deletions
@@ -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
@@ -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);
}
}