Skip to content

Conversation

@markushi
Copy link
Member

@markushi markushi commented Jan 12, 2026

📜 Description

Converts the MainActivity from Java to Kotlin, categorizing all our buttons a bit nicer too.

image

requires #5016 to be merged first.

💡 Motivation and Context

Modernizes the sample app to use Kotlin, which is now the recommended language for Android development. This makes the sample more representative of current best practices and simplifies future enhancements.

💚 How did you test it?

Manual testing of the sample app to ensure functionality remains unchanged.

📝 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

#skip-changelog

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@markushi markushi changed the title refactor(samples): Convert Android sample app MainActivity to Kotlin refactor(samples): Convert Android sample app to Jetpack Compose Jan 12, 2026
@markushi markushi changed the title refactor(samples): Convert Android sample app to Jetpack Compose refactor(samples): Convert main screen to Jetpack Compose Jan 16, 2026
@markushi markushi marked this pull request as ready for review January 16, 2026 11:06
@github-actions
Copy link
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

FileOutputStream(file).use { outputStream ->
val bytes = ByteArray(1024)
while (inputStream.read(bytes) != -1) {
outputStream.write(bytes)
Copy link

Choose a reason for hiding this comment

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

Bug: The file copy loop incorrectly writes the entire buffer instead of the number of bytes read, potentially corrupting the output file with garbage data from previous reads.
Severity: MEDIUM

Suggested Fix

Capture the number of bytes returned by inputStream.read(bytes) into a length variable. Then, call outputStream.write(bytes, 0, length) to ensure only the valid bytes that were just read are written to the output stream.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.kt#L153

Potential issue: The file copy logic reads from an `inputStream` into a `bytes` buffer
but does not use the return value of `inputStream.read(bytes)`, which indicates the
actual number of bytes read. Instead, it calls `outputStream.write(bytes)`, which writes
the entire buffer. On the final read, if the remaining data is smaller than the buffer
size, the buffer will contain valid data followed by stale data from the previous
iteration. Writing the full buffer appends this garbage data to the output file,
resulting in a corrupted file attachment for every Sentry event.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions
Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 350.63 ms 394.56 ms 43.93 ms
Size 1.58 MiB 2.19 MiB 620.05 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
dba088c 333.98 ms 381.16 ms 47.18 ms
91bb874 310.68 ms 359.24 ms 48.56 ms
d15471f 315.61 ms 360.22 ms 44.61 ms
27d7cf8 314.17 ms 347.00 ms 32.83 ms
a5ab36f 316.83 ms 394.54 ms 77.71 ms
5b66efd 308.67 ms 363.85 ms 55.18 ms
abfcc92 337.38 ms 427.39 ms 90.00 ms
fc5ccaf 279.11 ms 353.34 ms 74.23 ms
fcec2f2 328.91 ms 387.75 ms 58.84 ms
dba088c 365.46 ms 366.31 ms 0.85 ms

App size

Revision Plain With Sentry Diff
dba088c 1.58 MiB 2.13 MiB 558.99 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
a5ab36f 1.58 MiB 2.12 MiB 555.26 KiB
5b66efd 1.58 MiB 2.13 MiB 559.07 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.50 KiB
dba088c 1.58 MiB 2.13 MiB 558.99 KiB

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.

3 participants