mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-74322 (Bogus trigger of inspection 'Result of X not thrown')
This commit is contained in:
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2010 Bas Leijdekkers
|
||||
* Copyright 2007-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ThrowableInstanceNeverThrownInspection extends BaseInspection {
|
||||
@@ -167,7 +168,8 @@ public class ThrowableInstanceNeverThrownInspection extends BaseInspection {
|
||||
(PsiMethodCallExpression) grandParent;
|
||||
final PsiReferenceExpression methodExpression =
|
||||
methodCallExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName =
|
||||
methodExpression.getReferenceName();
|
||||
if (!"initCause".equals(methodName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ public class ThrowableResultOfMethodCallIgnoredInspection
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof PsiReturnStatement ||
|
||||
parent instanceof PsiThrowStatement) {
|
||||
parent instanceof PsiThrowStatement ||
|
||||
parent instanceof PsiExpressionList) {
|
||||
return;
|
||||
}
|
||||
if (!TypeUtils.expressionHasTypeOrSubtype(expression,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.siyeh.igtest.bugs.throwable_result_of_method_call_ignored;
|
||||
|
||||
|
||||
|
||||
public class A {
|
||||
public static void test() {
|
||||
try {
|
||||
firstNonNull(new Throwable(), null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(firstNonNull(e.getCause(), e));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T firstNonNull(T first, T second) {
|
||||
return first != null ? first : second;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>A.java</file>
|
||||
<line>8</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Throwable result of method call ignored</problem_class>
|
||||
<description>Result of <code>firstNonNull()</code> not thrown #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class ThrowableResultOfMethodCallIgnoredInspectionTest
|
||||
extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doTest("com/siyeh/igtest/bugs/throwable_result_of_method_call_ignored",
|
||||
new ThrowableResultOfMethodCallIgnoredInspection());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user