mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[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:
committed by
intellij-monorepo-bot
parent
6754c44959
commit
b2fd2611de
+6
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
public class BoxingInArrayDeclaration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Object[] arr = {1, 2};
|
||||
System.out.println(<warning descr="Condition 'arr[0] instanceof Integer' is always 'true'">arr[0] instanceof Integer</warning>);
|
||||
}
|
||||
}
|
||||
@@ -718,4 +718,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testEqualsTwoFields() { doTest();}
|
||||
public void testPureMethodReadsMutableArray() { doTest(); }
|
||||
public void testBoxingInConstructorArguments() { doTest(); }
|
||||
public void testBoxingInArrayDeclaration() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user