mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-181754 Result of 'xyz()' not thrown: do not report on always failing methods
This commit is contained in:
+11
-2
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer;
|
||||
import com.intellij.codeInspection.dataFlow.MethodContract;
|
||||
import com.intellij.codeInspection.dataFlow.StandardMethodContract;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
@@ -28,6 +31,8 @@ import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ThrowableNotThrownInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -105,8 +110,12 @@ public class ThrowableNotThrownInspection extends BaseInspection {
|
||||
InheritanceUtil.isInheritor(containingClass, CommonClassNames.JAVA_LANG_THROWABLE)) {
|
||||
return;
|
||||
}
|
||||
if ("propagate".equals(method.getName()) && "com.google.common.base.Throwables".equals(containingClass.getQualifiedName())) {
|
||||
return;
|
||||
List<StandardMethodContract> contracts = ControlFlowAnalyzer.getMethodContracts(method);
|
||||
if (contracts.size() == 1) {
|
||||
StandardMethodContract contract = contracts.get(0);
|
||||
if (contract.isTrivial() && contract.getReturnValue() == MethodContract.ValueConstraint.THROW_EXCEPTION) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
registerMethodCallError(expression, expression);
|
||||
}
|
||||
|
||||
+17
@@ -126,4 +126,21 @@ class Throwables {
|
||||
String message = cause.getMessage();
|
||||
System.out.println("message = " + message);
|
||||
}
|
||||
}
|
||||
|
||||
class FailTest {
|
||||
static RuntimeException fail() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
void testThrow(int x) {
|
||||
if(x < 0) {
|
||||
throw fail();
|
||||
}
|
||||
}
|
||||
void testNoThrow(int x) {
|
||||
if(x < 0) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user