capacitor-community / capacitor-community/play-integrity

NullPointerException as googleCloudProjectNumber is passed as Integer but parsed as Long

Open
#2 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
9
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Thank you for this Plugin. I found the following bug in my local setup.

The `data` JSONObject property of `PluginCall`, passed into `requestIntegrityToken` is treated as Integer so the `call.getLong("googleCloudProjectNumber")` produces a NullPointerException

**To Reproduce**
Steps to reproduce the behavior:
1. In the capacitor app, call
```
await PlayIntegrity.requestIntegrityToken({
nonce: crypto.randomUUID(),
googleCloudProjectNumber: 0,
});
```
3. Run `ionic cap sync`
5. Run the Android app
6. See error on startup:
```
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:816)
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 'long java.lang.Long.longValue()' on a null object reference
```
**Expected behavior**
Use the `int` value passed. Potentially the `googleCloudProjectNumber` JSON property could be String typed and the String parsed to long.

**Screenshots**
Screenshot 2024-05-16 at 16 58 42


JSON Object with Integer property


is instanceOf Integer true


is instanceOf Long false

**Smartphone (please complete the following information):**
- Device: Nexus 7 API 33 (Emulator)
- OS: Android 13 (Tiramisu)
- Capacitor-version: 6.0.0
- Typescript-version: 5.4.5

Contributor guide

Open the contributing guide

Research direction

Start at the Android implementation of requestIntegrityToken and inspect how PluginCall data is read around call.getLong("googleCloudProjectNumber"). Reproduce the supplied integer input, then verify that the request no longer throws a NullPointerException and that the expected project number is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.