mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-94910 (test case prepared)
This commit is contained in:
@@ -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 <code>provider.getResource()</code> may produce <code>java.lang.NullPointerException</code></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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user