Skip to content

Commit

Permalink
Add check null to handle NPE
Browse files Browse the repository at this point in the history
Credit to PR: briankabiro#86
  • Loading branch information
khuong-difisoft committed Jan 27, 2024
1 parent 0ac0b4a commit 9085493
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions android/src/main/java/com/react/SmsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ else if (fcontent != null && !fcontent.isEmpty())
c++;
}
}
cursor.close();
// I faced a NPE here, plus it's a good practice to have a null check.
if (cursor != null) {
cursor.close();
}
try {
successCallback.invoke(c, jsons.toString());
} catch (Exception e) {
errorCallback.invoke(e.getMessage());
}
} catch (JSONException e) {
errorCallback.invoke(e.getMessage());
return;
}
}

Expand Down Expand Up @@ -188,7 +190,6 @@ public void send(String addresses, String text, final Callback errorCallback, fi
successCallback.invoke("OK");
} catch (PendingIntent.CanceledException e) {
errorCallback.invoke(e.getMessage());
return;
}
}
return;
Expand All @@ -211,7 +212,6 @@ public void delete(Integer id, final Callback errorCallback, final Callback succ
return;
} catch (Exception e) {
errorCallback.invoke(e.getMessage());
return;
}
}

Expand Down

0 comments on commit 9085493

Please sign in to comment.