feat(ndk): handle native init failure code#4842
feat(ndk): handle native init failure code#4842hannojg wants to merge 2 commits intogetsentry:mainfrom
Conversation
| //noinspection UnstableApiUsage | ||
| io.sentry.ndk.SentryNdk.init(ndkOptions); | ||
| final int initResult = io.sentry.ndk.SentryNdk.init(ndkOptions); | ||
| if (initResult != 0) { |
There was a problem hiding this comment.
Bug: SentryNdk.init mock returns null, causing NullPointerException when auto-unboxed to int in tests.
Severity: HIGH | Confidence: 1.00
🔍 Detailed Analysis
The SentryNdk.init method is mocked using doAnswer in SentryNdkTest.kt. The production code expects SentryNdk.init to return an int, but the doAnswer lambda does not explicitly return a value. Mockito defaults to returning null in this scenario. When the code attempts to assign this null to final int initResult, Java's auto-unboxing mechanism triggers a NullPointerException. This prevents the tests from executing successfully.
💡 Suggested Fix
Modify the doAnswer lambda for io.sentry.ndk.SentryNdk.init in SentryNdkTest.kt to explicitly return an int value, such as 0, to match the expected return type.
🤖 Prompt for AI Agent
Fix this bug. In sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java
at line 78: The `SentryNdk.init` method is mocked using `doAnswer` in
`SentryNdkTest.kt`. The production code expects `SentryNdk.init` to return an `int`, but
the `doAnswer` lambda does not explicitly return a value. Mockito defaults to returning
`null` in this scenario. When the code attempts to assign this `null` to `final int
initResult`, Java's auto-unboxing mechanism triggers a `NullPointerException`. This
prevents the tests from executing successfully.
Did we get this right? 👍 / 👎 to inform future reviews.
|
Closing in favor of throwing an |
📜 Description
For initializing the android ndk we call via JNI into our
sentry.ccode, which returns aintfor success or failure.Right now the result of this init call is not checked.
💡 Motivation and Context
I have the hunch that in one of our clients app's the ndk sdk fails to properly initialize. Due to not propagating the result code up to java we don't throw if there have been an error during setup.
This PR can only though once this is merged in
getsentry/native:💚 How did you test it?
I'll be honest, i didn't as this seemed like a straight forward change 😅
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps