[java-dfa] getArrayElementValue: fix unboxing Object[] arrays

Fixes IDEA-288566 Wrong warning at array element instanceof when it was autoboxed

GitOrigin-RevId: f4c1a4bceca84db8842541ed0468af8785a839c7
This commit is contained in:
Tagir Valeev
2022-02-14 17:18:15 +07:00
committed by intellij-monorepo-bot
parent 6754c44959
commit b2fd2611de
3 changed files with 14 additions and 0 deletions

View File

@@ -97,6 +97,12 @@ public final class ArrayElementDescriptor extends JvmVariableDescriptor {
if (arrayPsiVar != null) {
PsiExpression constantArrayElement = ExpressionUtils.getConstantArrayElement(arrayPsiVar, index);
if (constantArrayElement != null) {
PsiType elementType = constantArrayElement.getType();
if (componentType instanceof DfReferenceType && elementType instanceof PsiPrimitiveType &&
!TypeConstraint.fromDfType(componentType).isPrimitiveWrapper()) {
componentType = DfTypes.typedObject(((PsiPrimitiveType)elementType).getBoxedType(constantArrayElement), Nullability.UNKNOWN)
.meet(componentType);
}
return getAdvancedExpressionDfaValue(factory, constantArrayElement, componentType);
}
}