udacity / ud851-Sunshine

Apache License 2.0
2k stars 4.5k forks source link

S10.02-Solution-SmarterSyncing - possible NPE #148

Open gshadows opened 6 years ago

gshadows commented 6 years ago

S10.02-Solution-SmarterSyncing - "SunshineSyncUtils.java"

Closing cursor without null check just after we assumed that it could be null. Possible same issue could be in all future solutions. At least in S10.03 solution.

//  COMPLETED (6) If it is empty or we have a null Cursor, sync the weather now!
if (null == cursor || cursor.getCount() == 0) {
    startImmediateSync(context);
}
/* Make sure to close the Cursor to avoid memory leaks! */
cursor.close(); // --> This could cause NPE because we just assumed cursor could be null.