java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference
Closed this issue ยท 6 comments
Hi
First of all, thank you for developing this plugin!
We have issues on Android and IOS when we call the authenticate-method. Getting a NullPointerException.
FATAL EXCEPTION: CapacitorPlugins Process: ***.***.app, PID: 17832 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:789) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference at com.aparajita.capacitor.biometricauth.BiometricAuthNative.authenticate(BiometricAuthNative.java:198) at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.os.HandlerThread.run(HandlerThread.java:67)
Any ideas?
Thanks!
Solved the issue myself.
I needed to check if biometric is available:
const result = await BiometricAuth.checkBiometry();
if (result.isAvailable) {
await BiometricAuth.authenticate({
allowDeviceCredential: true,
});
}
Shouldn't generate an exception if no biometry is available, I'll check into that.
@reinvanleirsberghe Thanks for the report, this has been fixed in 5.2.1. You can now safely call authenticate()
before calling checkBiometry()
.
Hello @aparajita, I think that this issue is happening again (with "@aparajita/capacitor-biometric-auth": "^7.1.1"
).
I cannot provide further implementation details, but given:
async mounted() {
try {
await BiometricAuth.authenticate(); // Use auth method without checking availability
await this.prefillCredentials();
await this.onLogin();
} catch (error) {
this.showErrorAlert(error);
}
}
It is causing the following error:
Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:800)
at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference
at com.aparajita.capacitor.biometricauth.BiometricAuthNative.internalAuthenticate(BiometricAuthNative.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:800)
at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
If I modify it to check the availability of biometry, it works as expected:
async mounted() {
try {
const checkBiometryResult = await BiometricAuth.checkBiometry();
if (checkBiometryResult.isAvailable) {
await BiometricAuth.authenticate();
await this.prefillCredentials();
await this.onLogin();
}
} catch (error) {
this.showErrorAlert(error);
}
}
Not a big issue itself, but just posting it here in case you want to check it, thanks! ๐
@rricamar v7.2.0 just released which allows you to safely call authenticate()
without calling checkBiometry()
first.
@rricamar v7.2.0 just released which allows you to safely call
authenticate()
without callingcheckBiometry()
first.
Thanks @aparajita, just tried it and it works perfectly! ๐