mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-139392 "Method Invocation may produce NPE" warning after call to assertThat().isNotNull from Google Truth framework
This commit is contained in:
+9
@@ -70,6 +70,7 @@ public class HardcodedContracts {
|
||||
else if ("junit.framework.Assert".equals(className) ||
|
||||
"org.junit.Assert".equals(className) ||
|
||||
"junit.framework.TestCase".equals(className) ||
|
||||
"com.google.common.truth.Truth".equals(className) ||
|
||||
"org.testng.Assert".equals(className) ||
|
||||
"org.testng.AssertJUnit".equals(className)) {
|
||||
return handleTestFrameworks(paramCount, className, methodName, call);
|
||||
@@ -111,6 +112,14 @@ public class HardcodedContracts {
|
||||
return Collections.singletonList(new MethodContract(constraints, THROW_EXCEPTION));
|
||||
}
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final PsiElement parent = call.getParent();
|
||||
if (parent instanceof PsiReferenceExpression &&
|
||||
"isNotNull".equals(((PsiReferenceExpression)parent).getReferenceName()) &&
|
||||
parent.getParent() instanceof PsiMethodCallExpression) {
|
||||
return Collections.singletonList(new MethodContract(new MethodContract.ValueConstraint[]{NULL_VALUE}, THROW_EXCEPTION));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
class Contracts {
|
||||
|
||||
private void checkNotNullValue(@Nullable Object o) {
|
||||
assertThat(o).isNotNull();
|
||||
System.out.println(o.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -355,6 +355,15 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testGoogleTruth() {
|
||||
myFixture.addClass("package com.google.common.truth; public class Truth { " +
|
||||
"public static Subject assertThat(Object o) {}\n" +
|
||||
"}");
|
||||
myFixture.addClass("package com.google.common.truth; public class Subject { public void isNotNull() {} }");
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testGuavaCheckNotNull() {
|
||||
myFixture.addClass("package com.google.common.base; public class Preconditions { " +
|
||||
"public static <T> T checkNotNull(T reference) {}\n" +
|
||||
|
||||
Reference in New Issue
Block a user