diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResourcesWarn.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResourcesWarn.java index 796de41f705c..b50a26e493cb 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResourcesWarn.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResourcesWarn.java @@ -23,21 +23,4 @@ class C { System.out.println(r); } } - - interface MyResourceProvider { - MyResource getResource(); - } - - void m3() throws Exception { - MyResourceProvider provider = null; - try (MyResource r = provider.getResource()) { - System.out.println(r); - } - } - - void m4() { - try (MyResource r = null) { - System.out.println(r); - } - } } \ No newline at end of file diff --git a/java/java-tests/testData/inspection/dataFlow/tryWithResources/expected.xml b/java/java-tests/testData/inspection/dataFlow/tryWithResources/expected.xml new file mode 100644 index 000000000000..a0ef40c50007 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/tryWithResources/expected.xml @@ -0,0 +1,8 @@ + + + + Test.java + 12 + Method invocation <code>provider.getResource()</code> may produce <code>java.lang.NullPointerException</code> + + diff --git a/java/java-tests/testData/inspection/dataFlow/tryWithResources/src/Test.java b/java/java-tests/testData/inspection/dataFlow/tryWithResources/src/Test.java new file mode 100644 index 000000000000..5045d8774868 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/tryWithResources/src/Test.java @@ -0,0 +1,22 @@ +class Test { + static class MyResource implements AutoCloseable { + @Override public void close() { } + } + + interface MyResourceProvider { + MyResource getResource(); + } + + void m1() throws Exception { + MyResourceProvider provider = null; + try (MyResource r = provider.getResource()) { + System.out.println(r); + } + } + + void m2() { + try (MyResource r = null) { + System.out.println(r); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 350deee39287..ae05e2cb85f5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -20,7 +20,6 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.compiler.JavacQuirksInspection; -import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.defUse.DefUseInspection; import com.intellij.codeInspection.redundantCast.RedundantCastInspection; @@ -147,7 +146,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { public void testNumericLiterals() throws Exception { doTest(false, false); } public void testMultiCatch() throws Exception { doTest(false, false); } public void testTryWithResources() throws Exception { doTest(false, false); } - public void testTryWithResourcesWarn() throws Exception { doTest(true, false, new DefUseInspection(), new DataFlowInspection()); } + public void testTryWithResourcesWarn() throws Exception { doTest(true, false, new DefUseInspection()); } public void testSafeVarargsApplicability() throws Exception { doTest(true, false); } public void testUncheckedGenericsArrayCreation() throws Exception { doTest(true, false); } public void testPreciseRethrow() throws Exception { doTest(false, false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index a938b477beac..0d8517550dea 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -114,6 +114,7 @@ public class DataFlowInspectionTest extends InspectionTestCase { public void testIDEADEV13153() { doTest15(); } public void testIDEADEV13156() { doTest15(); } public void testSwitchEnumCases() { doTest15(); } + public void testTryWithResources() { doTest15(true); } //public void testSCR15406() { doTest(); } // added by cdr, 2005 //public void testIDEADEV11033() { doTest15(); } // added by max, 2007