IDEA-94910 (test case prepared)

This commit is contained in:
Roman Shevchenko
2012-11-23 21:28:46 +01:00
parent 0586625266
commit 64282ae9dc
6 changed files with 179 additions and 125 deletions
@@ -0,0 +1,49 @@
import java.lang.Exception;
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 = <warning descr="Method invocation 'provider.getResource()' may produce 'java.lang.NullPointerException'">provider.getResource()</warning>) {
System.out.println(r);
}
}
void m2() {
try (MyResource r = null) {
System.out.println(r);
}
}
/*static class ResourcefulException1 extends Exception { }
static class ResourcefulException2 extends Exception { }
static class ExceptionalResource implements AutoCloseable {
@Override public void close() throws ResourcefulException1 { }
}
ExceptionalResource provideExceptionalResource() throws ResourcefulException2 {
return new ExceptionalResource();
}
void m3() {
try (ExceptionalResource r = provideExceptionalResource()) {
System.out.println(r);
}
catch (Exception e) {
if (e instanceof ResourcefulException1) {
System.out.println("1");
}
else if (e instanceof ResourcefulException2) {
System.out.println("2");
}
}
}*/
}
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>12</line>
<description>Method invocation &lt;code&gt;provider.getResource()&lt;/code&gt; may produce &lt;code&gt;java.lang.NullPointerException&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,22 +0,0 @@
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);
}
}
}