From ae0e4419ab871cd68fc312710a2f140f410703aa Mon Sep 17 00:00:00 2001 From: Aman Shekhar Date: Fri, 13 Aug 2021 09:58:06 +0530 Subject: [PATCH] Update SmsModule.java Implemented a Null Check, I was facing a NPE here. --- android/src/main/java/com/react/SmsModule.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/react/SmsModule.java b/android/src/main/java/com/react/SmsModule.java index 7a27616..ad130f1 100644 --- a/android/src/main/java/com/react/SmsModule.java +++ b/android/src/main/java/com/react/SmsModule.java @@ -118,7 +118,10 @@ 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) { @@ -126,7 +129,7 @@ else if (fcontent != null && !fcontent.isEmpty()) } } catch (JSONException e) { errorCallback.invoke(e.getMessage()); - return; + // return; 'return' is unnecessary as the last statement in a 'void' method. } } @@ -185,7 +188,7 @@ public void send(String addresses, String text, final Callback errorCallback, fi successCallback.invoke("OK"); } catch (PendingIntent.CanceledException e) { errorCallback.invoke(e.getMessage()); - return; + // return; 'return' is unnecessary as the last statement in a 'void' method. } } return; @@ -208,7 +211,7 @@ public void delete(Integer id, final Callback errorCallback, final Callback succ return; } catch (Exception e) { errorCallback.invoke(e.getMessage()); - return; + // return; 'return' is unnecessary as the last statement in a 'void' method. } }