I'm aware of that but actually it depends on the implementation you use, for example in SimpleConnectionFactory, con.close is called without checking if it is null or not. That's why I added the if block