Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null pointer exception and possible crash #415

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ public void onTagDiscovered(Tag tag) {

PluginResult result = new PluginResult(PluginResult.Status.OK, json);
result.setKeepCallback(true);
readerModeCallback.sendPluginResult(result);
if (readerModeCallback != null) {
readerModeCallback.sendPluginResult(result);
} else {
Log.i(TAG, "readerModeCallback is null - reader mode probably disabled in the meantime");
}

}
};
Expand Down Expand Up @@ -994,6 +998,10 @@ private void transceive(final byte[] data, final CallbackContext callbackContext
String error = "TagTechnology " + tagTechnologyClass.getName() + " does not have a transceive function";
Log.e(TAG, error, e);
callbackContext.error(error);
} catch (NullPointerException e) {
// This can happen if the tag has been closed while we're still working with it from the thread pool.
Log.e(TAG, e.getMessage(), e);
callbackContext.error(e.getMessage());
} catch (IllegalAccessException e) {
Log.e(TAG, e.getMessage(), e);
callbackContext.error(e.getMessage());
Expand Down