diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/HardcodedContracts.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/HardcodedContracts.java index 1fb320e6eda0..9c97f027dff1 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/HardcodedContracts.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/HardcodedContracts.java @@ -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(); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/GoogleTruth.java b/java/java-tests/testData/inspection/dataFlow/fixture/GoogleTruth.java new file mode 100644 index 000000000000..64dd1fa11a7e --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/GoogleTruth.java @@ -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()); + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 51dbce40c804..5280bb2f972e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -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 checkNotNull(T reference) {}\n" +