Skip to content

Conversation

buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Jul 29, 2025

📜 Description

Fixes an IndexOutOfBoundsException in the dropCommonAddresses function when processing stack traces on Kotlin/Native iOS. The issue was caused by incorrect index handling during the dropLastWhile operation.

💡 Motivation and Context

Closes #432

💚 How did you test it?

Manually tested: the following test crashes without the fix with IndexOutOfBoundsException

@Test
fun testDropCommon_ExcessiveTrailingMatches() {
    val commonAddresses = listOf<Long>(1, 2)
    val addresses = listOf<Long>(9, 8, 7, 2, 1, 2)
    val result = addresses.dropCommonAddresses(commonAddresses)

    // wont reach because it crashes
    assertEquals(listOf(9L, 8L, 7L), result)
}

Existing unit tests were run to verify the fix and ensure no regressions.

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • 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.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.

🔮 Next steps

Release this fix in an upcoming version to allow users to update their Sentry KMP dependency.


Open in Cursor Open in Web

Learn more about Cursor Agents

cursoragent and others added 5 commits July 29, 2025 10:13
Co-authored-by: giancarlo.buenaflor <giancarlo.buenaflor@sentry.io>
Co-authored-by: giancarlo.buenaflor <giancarlo.buenaflor@sentry.io>
@buenaflor buenaflor marked this pull request as ready for review July 30, 2025 15:04
@buenaflor buenaflor requested a review from romtsn as a code owner July 30, 2025 15:04
@buenaflor
Copy link
Contributor Author

@sentry review

@buenaflor buenaflor enabled auto-merge (squash) July 31, 2025 09:31
@buenaflor buenaflor changed the title Fix Sentry kmp stack trace crash on ios Fix KotlinIndexOutOfBounds crash on iOS Jul 31, 2025
@buenaflor buenaflor changed the title Fix KotlinIndexOutOfBounds crash on iOS Fix IndexOutOfBounds crash on iOS Jul 31, 2025
@buenaflor buenaflor requested a review from markushi July 31, 2025 09:32
Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

LGTM!

@buenaflor buenaflor merged commit f2d2f3f into main Jul 31, 2025
9 checks passed
@buenaflor buenaflor deleted the cursor/fix-sentry-kmp-stack-trace-crash-on-ios-f0c7 branch July 31, 2025 10:18
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.

Uncaught Kotlin exception: kotlin.IndexOutOfBoundsException:

3 participants