From 82f213c6ab8d8c94eb7599fdcb81e96cc000261e Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 11 Oct 2018 16:49:34 +0200 Subject: [PATCH] IG: fix NPE on invalid code (IDEA-200213) --- .../siyeh/ig/style/UnnecessaryParenthesesInspection.java | 6 ++++-- .../UnnecessaryParenthesesInspection.java | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java index 4bdc6f7238cd..956687f2a083 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2018 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ParenthesesUtils; +import com.siyeh.ipp.psiutils.ErrorUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -120,7 +121,8 @@ public class UnnecessaryParenthesesInspection extends BaseInspection implements return; } } - if (!ParenthesesUtils.areParenthesesNeeded(expression, ignoreClarifyingParentheses)) { + if (!ParenthesesUtils.areParenthesesNeeded(expression, ignoreClarifyingParentheses) && + !ErrorUtil.containsError(expression) && !ErrorUtil.containsError(expression.getExpression())) { registerError(expression); return; } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java index dd63ad8bc997..f88e28e1b184 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java @@ -129,3 +129,9 @@ public class UnnecessaryParenthesesInspection return (a -> a)=1; } } +class A{ + + A() { + ((<x>) + } +}