Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/TryWithResourcesCloseThrows.java
Tagir Valeev ff31ae4367 [java-dfa] Assume that Closable.close() may throw unchecked exception.
Fixes IDEA-304296 False positive warnings and non-equivalent quick fixes in control flow analysis of try-with-resources not taking into account possible exceptions thrown from close()

GitOrigin-RevId: df8c30a26d67817fb6412c378fa1fe11fb2e007b
2022-10-26 17:17:32 +00:00

24 lines
476 B
Java

// IDEA-304296
class Example {
public static void main(String[] args) {
boolean done = false;
try (final ThrowsOnClose resource = new ThrowsOnClose()) {
resource.foo();
done = true;
} catch (RuntimeException e) {
if (!done) {
throw e;
}
}
}
private static class ThrowsOnClose implements AutoCloseable {
public void foo() {
}
@Override
public void close() {
throw new RuntimeException();
}
}
}