Skip to content

fix(android): Avoid Math floor APIs#5743

Merged
adinauer merged 9 commits into
mainfrom
fix/android-floor-div
Jul 8, 2026
Merged

fix(android): Avoid Math floor APIs#5743
adinauer merged 9 commits into
mainfrom
fix/android-floor-div

Conversation

@adinauer

@adinauer adinauer commented Jul 8, 2026

Copy link
Copy Markdown
Member

📜 Description

Replace Math.floorDiv and Math.floorMod usage in SentryIso8601Utils with a package-private SentryMath helper.

💡 Motivation and Context

Fixes #5741

SentryIso8601Utils lives in the shared sentry module and is reachable from Android. Android supports minSdk 21 in this repo, but java.lang.Math.floorDiv/floorMod are only available on newer Android API levels. Calling them from shared code can crash Android apps on supported older devices with NoSuchMethodError.

The replacement helper adapts Apache-licensed Guava LongMath floor division logic and adds matching attribution in THIRD_PARTY_NOTICES.md. floorMod is implemented through floorDiv so it matches Java Math.floorMod for both positive and negative divisors.

💚 How did you test it?

  • ./gradlew :sentry:test --tests "io.sentry.vendor.SentryMathTest" --tests "io.sentry.DateUtilsTest"
  • ./gradlew :sentry:animalsnifferMain
  • ./gradlew spotlessApply apiDump
  • rg -n "\\bMath\\.(floorDiv|floorMod)" sentry/src/main/java sentry-android-core/src/main/java -g '*.java' -g '*.kt'

📝 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

None.

adinauer and others added 2 commits July 8, 2026 11:19
Replace Math.floorDiv and Math.floorMod in the shared timestamp formatter with local helpers so Android consumers do not call APIs unavailable on older supported Android versions.

Co-Authored-By: Claude <noreply@anthropic.com>
@adinauer adinauer marked this pull request as ready for review July 8, 2026 09:24
@sentry

sentry Bot commented Jul 8, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.47.0 (1) release

⚙️ sentry-android Build Distribution Settings

Comment thread sentry/src/main/java/io/sentry/vendor/SentryIso8601Utils.java Outdated
@runningcode

Copy link
Copy Markdown
Contributor

We should def add a test for this.

adinauer and others added 3 commits July 8, 2026 11:47
Move the floor division and modulo replacements into a dedicated SentryMath class with Android Open Source Project attribution and third-party notices. Add tests that compare the helper behavior against Java Math for edge cases.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove the incorrect AOSP attribution for SentryMath. The referenced Android Math source is GPLv2 with the Classpath exception, not Apache 2.0. Implement the helpers directly from quotient and remainder semantics instead.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 316.75 ms 357.76 ms 41.01 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
4c04bb8 350.71 ms 413.63 ms 62.92 ms
bb0ff41 315.84 ms 350.76 ms 34.92 ms
7c1a728 289.46 ms 368.15 ms 78.69 ms
ff8eea4 313.42 ms 337.08 ms 23.66 ms
bbc35bb 298.53 ms 372.17 ms 73.64 ms
91bb874 311.00 ms 363.47 ms 52.47 ms
abfcc92 337.38 ms 427.39 ms 90.00 ms
ae7fed0 293.84 ms 380.22 ms 86.38 ms
3998a95 415.94 ms 478.54 ms 62.60 ms
d15471f 307.28 ms 381.85 ms 74.57 ms

App size

Revision Plain With Sentry Diff
4c04bb8 0 B 0 B 0 B
bb0ff41 0 B 0 B 0 B
7c1a728 0 B 0 B 0 B
ff8eea4 1.58 MiB 2.28 MiB 718.64 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
ae7fed0 1.58 MiB 2.12 MiB 551.77 KiB
3998a95 1.58 MiB 2.10 MiB 532.96 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB

Previous results on branch: fix/android-floor-div

Startup times

Revision Plain With Sentry Diff
d888d1b 335.53 ms 412.98 ms 77.45 ms

App size

Revision Plain With Sentry Diff
d888d1b 0 B 0 B 0 B

adinauer and others added 2 commits July 8, 2026 12:11
Use Apache-licensed Guava LongMath floor division logic for SentryMath and restore the matching third-party attribution. Keep floorMod implemented through floorDiv so it matches Math.floorMod for negative divisors too.

Co-Authored-By: Claude <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b5c0278. Configure here.

Comment thread sentry/src/main/java/io/sentry/vendor/SentryMath.java
Comment thread CHANGELOG.md Outdated
Update the unreleased changelog entry to call out the Android API compatibility failure more directly.

Co-Authored-By: Claude <noreply@anthropic.com>
@adinauer adinauer merged commit a5db1a2 into main Jul 8, 2026
69 of 71 checks passed
@adinauer adinauer deleted the fix/android-floor-div branch July 8, 2026 12:04
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.

java.lang.NoSuchMethodError: java.lang.Math.floorDiv(JI)J

4 participants