mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-383492 Wrong warning when casting to (Integer & Serializable)
GitOrigin-RevId: 94b399d73658082878f8102e24fc2659173bae08
This commit is contained in:
committed by
intellij-monorepo-bot
parent
87d0a7bd6c
commit
fccce01896
@@ -1430,10 +1430,11 @@ public final class TypeConversionUtil {
|
||||
public static boolean isPrimitiveWrapper(@NotNull String fullyQualifiedName) {
|
||||
return PRIMITIVE_WRAPPER_FQNS.contains(fullyQualifiedName);
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
public static boolean isAssignableFromPrimitiveWrapper(@Nullable PsiType type) {
|
||||
if (type == null) return false;
|
||||
if (isPrimitiveWrapper(type)) return true;
|
||||
if (isPrimitiveWrapper(type)) return true; //leave it as short path; for intersection, there is a double check
|
||||
for (PsiType component : type instanceof PsiIntersectionType ? ((PsiIntersectionType)type).getConjuncts() : new PsiType[]{type}) {
|
||||
if (!(component instanceof PsiClassType)) return false;
|
||||
if (component.equalsToText(JAVA_LANG_OBJECT)) continue;
|
||||
@@ -1442,6 +1443,7 @@ public final class TypeConversionUtil {
|
||||
if (component.equalsToText("java.lang.constant.Constable")) continue;
|
||||
if (component.equalsToText("java.lang.constant.ConstantDesc")) continue;
|
||||
if (PsiTypesUtil.classNameEquals(component, JAVA_LANG_COMPARABLE)) continue;
|
||||
if (isPrimitiveWrapper(component)) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.io.Serializable;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
var x = (Integer & Serializable) 10;
|
||||
System.out.println(x + 1);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -762,7 +762,10 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testIoContracts() { doTest(); }
|
||||
public void testGetTernary() { doTest(); }
|
||||
public void testClosureInConstructor() { doTest(); }
|
||||
|
||||
public void testCastIntersectionWithSerializable() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_11, () -> doTest());
|
||||
}
|
||||
|
||||
public void testHugeMethodFlow() { doTest(); }
|
||||
public void testPrivateFieldPureMethod() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user