From 5d177ab16ad1387f71aa6a12f8a40ec713858ed9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 2 Apr 2015 15:34:29 +0200 Subject: [PATCH] IDEA-138606 ("Result of '...' not thrown" false positive if case of simple getter) --- ...ableResultOfMethodCallIgnoredInspection.java | 6 +++--- ... => ThrowableResultOfMethodCallIgnored.java} | 17 ++++++++++++++++- ...ResultOfMethodCallIgnoredInspectionTest.java | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) rename plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/{A.java => ThrowableResultOfMethodCallIgnored.java} (60%) 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 080a6e58c409..5b44ddaeb01c 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-2014 Bas Leijdekkers + * Copyright 2008-2015 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ package com.siyeh.ig.bugs; import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.InheritanceUtil; +import com.intellij.psi.util.PropertyUtil; 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; @@ -74,7 +74,7 @@ public class ThrowableResultOfMethodCallIgnoredInspection return; } final PsiMethod method = expression.resolveMethod(); - if (method == null) { + if (method == null || PropertyUtil.isSimpleGetter(method)) { return; } if (!method.hasModifierProperty(PsiModifier.STATIC)) { 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/ThrowableResultOfMethodCallIgnored.java similarity index 60% rename from plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/A.java rename to plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored/ThrowableResultOfMethodCallIgnored.java index ee413b9cfe9e..67140bb478e3 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/ThrowableResultOfMethodCallIgnored.java @@ -2,7 +2,7 @@ package com.siyeh.igtest.bugs.throwable_result_of_method_call_ignored; -public class A { +public class ThrowableResultOfMethodCallIgnored { public static void test() { try { firstNonNull(new Throwable(), null); @@ -24,3 +24,18 @@ public class A { return new RuntimeException(); } } +class ResWrap { + private String payload; + private Throwable error; + + public Throwable getError() { + return error; + } + public ResWrap service() { + final ResWrap result = new ResWrap(); + if (result.getError() == null) { + //rememberResult(result.payload); + } + return result; + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java index adeb8aeca497..102f480f0d2b 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ThrowableResultOfMethodCallIgnoredInspectionTest.java @@ -6,7 +6,7 @@ import com.siyeh.ig.LightInspectionTestCase; public class ThrowableResultOfMethodCallIgnoredInspectionTest extends LightInspectionTestCase { - public void testA() throws Exception { + public void testThrowableResultOfMethodCallIgnored() throws Exception { doTest(); }