Skip to content

Commit

Permalink
fix Sentry Empty ID, replace dashes if 36 char uuid String is passed …
Browse files Browse the repository at this point in the history
…to SentryId constructor
  • Loading branch information
lbloder committed Nov 8, 2024
1 parent 57d0a9b commit 45c3cbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sentry/src/main/java/io/sentry/protocol/SentryId.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

public final class SentryId implements JsonSerializable {

public static final SentryId EMPTY_ID = new SentryId(StringUtils.PROPER_NIL_UUID);
public static final SentryId EMPTY_ID =
new SentryId(StringUtils.PROPER_NIL_UUID.replace("-", ""));

private final @NotNull LazyEvaluator<String> lazyStringValue;

Expand All @@ -41,7 +42,11 @@ public SentryId(final @NotNull String sentryIdString) {
+ "or 36 characters long (completed UUID). Received: "
+ sentryIdString);
}
this.lazyStringValue = new LazyEvaluator<>(() -> normalized);
if (normalized.length() == 36) {
this.lazyStringValue = new LazyEvaluator<>(() -> normalized.replace("-", ""));
} else {
this.lazyStringValue = new LazyEvaluator<>(() -> normalized);
}
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions sentry/src/test/java/io/sentry/protocol/SentryIdTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class SentryIdTest {
assertEquals("00000000000000000000000000000000", id.toString())
}

@Test
fun `dashes are stripped if initialized with 36char uuid string`() {
val uuidString = UUID.randomUUID().toString()
val id = SentryId(uuidString)
assertEquals(uuidString.replace("-", ""), id.toString())
}

@Test
fun `UUID is not generated on initialization`() {
val uuid = SentryUUID.generateSentryId()
Expand Down

0 comments on commit 45c3cbe

Please sign in to comment.