Skip to content

Commit

Permalink
add null check for constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
nnym committed Feb 12, 2022
1 parent 6c60c75 commit 02b0587
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion idea/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</description>
<change-notes>
<![CDATA[
Lambda and inner class variables may be reassigned.
Fixed an error that arose from empty constructors.
]]>
</change-notes>
<depends>com.intellij.modules.platform</depends>
Expand Down
8 changes: 3 additions & 5 deletions idea/source/net/auoeke/uncheck/intellij/HighlightFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ private static boolean matches(HighlightInfo info, String key, String... argumen
}

private static boolean initialized(PsiMethod constructor, PsiField field) {
var body = constructor.getBody();

if (body == null) {
if (constructor == null || constructor.getBody() == null) {
return false;
}

return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, body)
|| Stream.of(body.getChildren())
return HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, constructor.getBody())
|| Stream.of(constructor.getBody().getChildren())
.filter(PsiExpressionStatement.class::isInstance)
.map(statement -> ((PsiExpressionStatement) statement).getExpression())
.anyMatch(expression -> expression instanceof PsiMethodCallExpression && initialized(((PsiMethodCallExpression) expression).resolveMethod(), field));
Expand Down

0 comments on commit 02b0587

Please sign in to comment.