Skip to content

Commit

Permalink
fix: make correct hash calculation for GenericObject type (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jul 10, 2019
1 parent f57dfb3 commit e4fc677
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public String toString() {
}

private static class ObjectType extends KnownType {
private final String objName;
protected final String objName;

public ObjectType(String obj) {
this.objName = Utils.cleanObjectName(obj);
Expand Down Expand Up @@ -269,15 +269,18 @@ public GenericObject(String obj, ArgType[] generics) {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit e4fc677

Please sign in to comment.