IDEA-138606 ("Result of '...' not thrown" false positive if case of simple getter)

This commit is contained in:
Bas Leijdekkers
2015-04-02 15:35:29 +02:00
parent b269474c62
commit 5d177ab16a
3 changed files with 20 additions and 5 deletions
@@ -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)) {
@@ -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 {
<warning descr="Result of 'firstNonNull()' not thrown">firstNonNull</warning>(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;
}
}
@@ -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();
}