Skip to content

Conversation

@hannojg
Copy link

@hannojg hannojg commented Oct 28, 2025

📜 Description

For initializing the android ndk we call via JNI into our sentry.c code, which returns a int for 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

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@hannojg hannojg changed the title feat(ndk): handle native init failure code and document change feat(ndk): handle native init failure code Oct 28, 2025
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.init(ndkOptions);
final int initResult = io.sentry.ndk.SentryNdk.init(ndkOptions);
if (initResult != 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant