From ebe984524e55dfc66d39f96be7d9fcc9d89dda53 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 10 Jun 2024 17:12:21 +0200 Subject: [PATCH] [java-inspections] ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection: fix NPE in case of no qualifier Fixes EA-1243433 - NPE: DfaUtil.getDataflowContext GitOrigin-RevId: e807a5e9675a9fbbc454fd29be661a878efcf04f --- .../com/intellij/codeInspection/dataFlow/CommonDataflow.java | 4 ++-- ...eduledThreadPoolExecutorWithZeroCoreThreadsInspection.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CommonDataflow.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CommonDataflow.java index bbcb53882380..9fb3e8a5f5e2 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CommonDataflow.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/CommonDataflow.java @@ -321,7 +321,7 @@ public final class CommonDataflow { * @return DfType for that expression. May return {@link DfType#TOP} if no information from dataflow is known about this expression */ @NotNull - public static DfType getDfType(PsiExpression expression) { + public static DfType getDfType(@NotNull PsiExpression expression) { return getDfType(expression, false); } @@ -331,7 +331,7 @@ public final class CommonDataflow { * @return DfType for that expression. May return {@link DfType#TOP} if no information from dataflow is known about this expression */ @NotNull - public static DfType getDfType(PsiExpression expression, boolean ignoreAssertions) { + public static DfType getDfType(@NotNull PsiExpression expression, boolean ignoreAssertions) { DataflowResult result = getDataflowResult(expression); if (result == null) return DfType.TOP; expression = PsiUtil.skipParenthesizedExprDown(expression); diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection.java index 45c98d872351..a6180f60c93d 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection.java @@ -40,6 +40,7 @@ public final class ScheduledThreadPoolExecutorWithZeroCoreThreadsInspection exte final PsiExpression arg = getZeroArgument(expression.getArgumentList()); if (arg == null) return; final PsiExpression qualifier = expression.getMethodExpression().getQualifierExpression(); + if (qualifier == null) return; final TypeConstraint constraint = TypeConstraint.fromDfType(CommonDataflow.getDfType(qualifier)); final PsiType type = constraint.getPsiType(expression.getProject()); if (!TypeUtils.typeEquals(SCHEDULED_THREAD_POOL_EXECUTOR_CLASS_NAME, type)) return;