java - null checking with traditional finally block for closing resources -


there examples on net checking null before invoking close() open resource.

final inputstream in = ...; // may throw ioexception try {     // something. } {     if (in != null) { // required?         in.close();     } } 

i've been done without null-checking-if.

final inputstream in = ...; // may throw ioexception try {                  // when reached line 'in' never null, be?     // something. } {     in.close(); // no null check required, wrong? } 

if there no chance of resource becoming null in of code execution paths there's 0 need null check.

you doing right thing.


Comments