Skip to content

Commit 04bb98f

Browse files
fix(android): Skip dist fallback when release has no version code (#6450)
* fix(android): Skip dist fallback when release has no version code ApplicationExitInfoEventProcessor derived dist from the text after '+' in the release. Without a '+', indexOf returned -1 and the whole release became dist, which Relay rejects for characters like '@'. Co-Authored-By: Gene Wright <gene.wright@sentry.io> * changelog Co-Authored-By: Gene Wright <gene.wright@sentry.io> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Gene Wright <gene.wright@sentry.io>
1 parent 084c3cb commit 04bb98f

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Keep UI profiling running when `startProfiler` is called before a requested stop takes effect at the end of the current chunk ([#6291](https://github.com/getsentry/sentry-java/pull/6291))
1919
- Before, the start call was ignored and the profiler still stopped at the end of the chunk, even in `TRACE` mode while sampled spans were active. On API 34 and lower, every later profile also stopped after one chunk.
2020
- Refuse to send data to servers whose certificate was issued by one of the leaked eMudhra intermediates (CVE-2026-111943) ([#6336](https://github.com/getsentry/sentry-java/pull/6336))
21+
- Stop sending the whole release as `dist` on ANR and app-exit events when the release has no `+versionCode` ([#6450](https://github.com/getsentry/sentry-java/pull/6450))
22+
- Relay rejected these values (e.g. `invalid character '@'`). `dist` is now left empty unless `options.dist` is set or the release contains a version code.
2123

2224
### Dependencies
2325

‎sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,13 @@ private void setDist(
532532
event.setDist(getLaunchOption(DIST_FILENAME, String.class, options.getDist(), optionsSource));
533533
}
534534
// if there's no user-set dist, fall back to versionCode from the release string
535+
// (package@versionName+versionCode). Releases without a versionCode leave dist empty.
535536
if (event.getDist() == null) {
536537
final String release = event.getRelease();
537538
if (release != null) {
538-
try {
539-
final String versionCode = release.substring(release.indexOf('+') + 1);
540-
event.setDist(versionCode);
541-
} catch (Throwable e) {
542-
options
543-
.getLogger()
544-
.log(SentryLevel.WARNING, "Failed to parse release from scope cache: %s", release);
539+
final int versionCodeSeparator = release.indexOf('+');
540+
if (versionCodeSeparator != -1) {
541+
event.setDist(release.substring(versionCodeSeparator + 1));
545542
}
546543
}
547544
}

‎sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,32 @@ class ApplicationExitInfoEventProcessorTest {
746746
assertEquals("232", processed!!.dist)
747747
}
748748

749+
@Test
750+
fun `if dist is not persisted and release has no version code, leaves dist empty`() {
751+
val hint = HintUtils.createWithTypeCheckHint(BackfillableHint())
752+
753+
val processor = fixture.getSut(tmpDir)
754+
fixture.persistOptions(RELEASE_FILENAME, "io.sentry.samples@1.2")
755+
756+
val processed = processor.process(SentryEvent(), hint)
757+
758+
assertEquals("io.sentry.samples@1.2", processed!!.release)
759+
assertNull(processed.dist)
760+
}
761+
762+
@Test
763+
fun `if dist is not persisted and options release has no version code, leaves dist empty`() {
764+
val hint = HintUtils.createWithTypeCheckHint(AbnormalExitHint(timestamp = 2_000))
765+
val processor = fixture.getSut(tmpDir)
766+
fixture.options.release = "io.sentry.samples@1.2"
767+
setLastUpdateTime(1_000)
768+
769+
val processed = processor.process(SentryEvent(), hint)!!
770+
771+
assertEquals("io.sentry.samples@1.2", processed.release)
772+
assertNull(processed.dist)
773+
}
774+
749775
@Test
750776
fun `merges user`() {
751777
val hint = HintUtils.createWithTypeCheckHint(BackfillableHint())

0 commit comments

Comments
 (0)