From 6c60c751262de0326d363f4a3e7476d794bb407d Mon Sep 17 00:00:00 2001 From: Mohamed Maaliki Date: Sat, 12 Feb 2022 13:18:27 +0000 Subject: [PATCH] add `null` checks for constructor body --- idea/build.gradle | 2 +- .../uncheck/intellij/HighlightFilter.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/idea/build.gradle b/idea/build.gradle index 5f89031..a3baf46 100644 --- a/idea/build.gradle +++ b/idea/build.gradle @@ -2,7 +2,7 @@ plugins { id("org.jetbrains.intellij").version("latest.integration") } -version("0.2.0") +version("0.2.1") javaVersion(11) sourceSets { diff --git a/idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java b/idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java index 5bdea83..4e21a2d 100644 --- a/idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java +++ b/idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java @@ -81,17 +81,16 @@ private static boolean matches(HighlightInfo info, String key, String... argumen } private static boolean initialized(PsiMethod constructor, PsiField field) { - return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, constructor.getBody()) || Stream.of(constructor.getBody().getChildren()).anyMatch(child -> { - if (child instanceof PsiExpressionStatement) { - var expression = ((PsiExpressionStatement) child).getExpression(); - - if (expression instanceof PsiMethodCallExpression) { - return initialized(((PsiMethodCallExpression) expression).resolveMethod(), field); - } - } + var body = constructor.getBody(); + if (body == null) { return false; - }); + } + return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, body) + || Stream.of(body.getChildren()) + .filter(PsiExpressionStatement.class::isInstance) + .map(statement -> ((PsiExpressionStatement) statement).getExpression()) + .anyMatch(expression -> expression instanceof PsiMethodCallExpression && initialized(((PsiMethodCallExpression) expression).resolveMethod(), field)); } }