In my app i want to close my cursor in finally statement like this :
Cursor cursor = null;
try {
    // some code
} finally {
     cursor.close();
}
My IDE highlight cursor.close(); and tell :
This method can produce
nullPointerException
And suggest to way to correct it (im using intelij idea) :
First: 
assert cursor != null;
cursor.close();
Second:
if (cursor != null) {
   cursor.close();
} 
I want to know what is difference between them and which way is better approach ?
 
    