-
-
Notifications
You must be signed in to change notification settings - Fork 465
refactor(samples): Convert main screen to Jetpack Compose #5017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. 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) |
There was a problem hiding this comment.
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.
Performance metrics 🚀
|
| 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 |
📜 Description
Converts the MainActivity from Java to Kotlin, categorizing all our buttons a bit nicer too.
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
sendDefaultPIIis enabled.🔮 Next steps
#skip-changelog