提交 89dbae8f 编写于 作者: S Skylot

fix: resolve NPE while compare outer generic types

上级 5eec8f75
......@@ -174,15 +174,24 @@ public class TypeCompare {
// both wildcards
return compareWildcardTypes(first, second);
}
// compare generics arrays
ArgType[] firstGenericTypes = first.getGenericTypes();
ArgType[] secondGenericTypes = second.getGenericTypes();
int len = firstGenericTypes.length;
if (len == secondGenericTypes.length) {
for (int i = 0; i < len; i++) {
TypeCompareEnum res = compareTypes(firstGenericTypes[i], secondGenericTypes[i]);
if (res != EQUAL) {
return res;
if (firstGenericTypes == null || secondGenericTypes == null) {
// check outer types
ArgType firstOuterType = first.getOuterType();
ArgType secondOuterType = second.getOuterType();
if (firstOuterType != null && secondOuterType != null) {
return compareTypes(firstOuterType, secondOuterType);
}
} else {
// compare generics arrays
int len = firstGenericTypes.length;
if (len == secondGenericTypes.length) {
for (int i = 0; i < len; i++) {
TypeCompareEnum res = compareTypes(firstGenericTypes[i], secondGenericTypes[i]);
if (res != EQUAL) {
return res;
}
}
}
}
......
......@@ -155,6 +155,16 @@ public class TypeCompareTest {
check(vType, ArgType.STRING, TypeCompareEnum.CONFLICT);
}
@Test
public void compareOuterGenerics() {
ArgType hashMapType = object("java.util.HashMap");
ArgType innerEntrySetType = object("EntrySet");
ArgType firstInstance = ArgType.outerGeneric(generic(hashMapType, STRING, STRING), innerEntrySetType);
ArgType secondInstance = ArgType.outerGeneric(generic(hashMapType, OBJECT, OBJECT), innerEntrySetType);
check(firstInstance, secondInstance, TypeCompareEnum.NARROW);
}
private void firstIsNarrow(ArgType first, ArgType second) {
check(first, second, TypeCompareEnum.NARROW);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册