SuspiciousArrayMethodCallInspection: erased types are compared (fixes IDEA-172742). As the corresponding argument accepts Object or Object[], exact generic signature cannot be always inferred.

This commit is contained in:
Tagir Valeev
2017-05-12 11:11:05 +07:00
parent d83bfc0b76
commit ed2d5b33fe
3 changed files with 29 additions and 1 deletions

View File

@@ -72,6 +72,8 @@ public class SuspiciousArrayMethodCallInspection extends BaseJavaBatchLocalInspe
PsiType arrayElementType = ((PsiArrayType)arrayType).getComponentType();
// incompatible primitive array will be reported anyways as compilation error
if (arrayElementType instanceof PsiPrimitiveType) return;
elementType = TypeConversionUtil.erasure(elementType);
arrayElementType = TypeConversionUtil.erasure(arrayElementType);
if (!TypeConversionUtil.areTypesConvertible(elementType, arrayElementType)) {
holder.registerProblem(element, InspectionsBundle.message("inspection.suspicious.array.method.call.problem.element"));
}
@@ -85,6 +87,8 @@ public class SuspiciousArrayMethodCallInspection extends BaseJavaBatchLocalInspe
PsiType array2ElementType = ((PsiArrayType)array2Type).getComponentType();
// incompatible primitive array will be reported anyways as compilation error
if (array1ElementType instanceof PsiPrimitiveType || array2ElementType instanceof PsiPrimitiveType) return;
array1ElementType = TypeConversionUtil.erasure(array1ElementType);
array2ElementType = TypeConversionUtil.erasure(array2ElementType);
if (!TypeConversionUtil.areTypesConvertible(array1ElementType, array2ElementType) ||
!TypeConversionUtil.areTypesConvertible(array2ElementType, array1ElementType)) {
holder.registerProblem(context, InspectionsBundle.message("inspection.suspicious.array.method.call.problem.arrays"));