From b250cbb829249ede9984e3535bed4826cc9429af Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 26 Jun 2014 16:06:12 +0200 Subject: [PATCH] IDEA-126352 (bug in "Throwable result of method call ignored" inspection) --- .../ThrowableResultOfMethodCallIgnoredInspection.java | 8 ++++---- .../bugs/throwable_result_of_method_call_ignored/A.java | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java index cbf33121dd44..080a6e58c409 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2011 Bas Leijdekkers + * Copyright 2008-2014 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.util.Query; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; @@ -57,11 +58,10 @@ public class ThrowableResultOfMethodCallIgnoredInspection extends BaseInspectionVisitor { @Override - public void visitMethodCallExpression( - PsiMethodCallExpression expression) { + public void visitMethodCallExpression(PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); PsiElement parent = expression.getParent(); - while (parent instanceof PsiParenthesizedExpression) { + while (parent instanceof PsiParenthesizedExpression || parent instanceof PsiTypeCastExpression) { parent = parent.getParent(); } if (parent instanceof PsiReturnStatement || diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java index 3e25ccbfecc1..ee413b9cfe9e 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java @@ -15,4 +15,12 @@ public class A { public static T firstNonNull(T first, T second) { return first != null ? first : second; } + + void m() { + throw (RuntimeException) b(); + } + + public Exception b() { + return new RuntimeException(); + } }