Java / Exception
What happens when the AutoCloseable resource is null in Java Try-With-Resource?
A null resource in try-with-resources is skipped; close is not called. The try body still runs. A later NPE is from your code, not from close.
A resource is closed only if it is initialized to a non-null value. If the reference is null, no attempt is made to call close() on it, no NullPointerException is thrown, and it works as expected.
More Related questions...