Conversation
Trailing or leading whitespace in the DSN string (commonly introduced by copy-paste) causes a URISyntaxException that crashes the application on startup. Trim the DSN before passing it to the URI constructor. Fixes GH-5087 Co-Authored-By: Claude <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
🤖 This preview updates automatically when you update the PR. |
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| try { | ||
| Objects.requireNonNull(dsn, "The DSN is required."); | ||
| final URI uri = new URI(dsn).normalize(); | ||
| final String dsnString = Objects.requireNonNull(dsn, "The DSN is required.").trim(); |
There was a problem hiding this comment.
DSN hash calculated before trim causes cache fragmentation
Medium Severity
The DSN is trimmed in the constructor for parsing, but SentryOptions.setDsn calculates the hash from the untrimmed string. This means "dsn" and "dsn " parse identically but create different cache directories, fragmenting cached envelopes, sessions, breadcrumbs, and scope data. Users switching between whitespace variants (config changes, programmatic vs manifest) lose access to previously cached data.
| Objects.requireNonNull(dsn, "The DSN is required."); | ||
| final URI uri = new URI(dsn).normalize(); | ||
| final String dsnString = Objects.requireNonNull(dsn, "The DSN is required.").trim(); | ||
| final URI uri = new URI(dsnString).normalize(); |
There was a problem hiding this comment.
Missing empty-string validation after trim causes confusing error
Low Severity
After trimming, there's no check if dsnString is empty before URI parsing. A whitespace-only DSN like " " trims to "", which creates a valid URI with null scheme, causing error message "Invalid DSN scheme: null". This is confusing because it suggests a scheme problem rather than an empty DSN. Before this change, whitespace-only DSNs threw URISyntaxException about illegal characters, which was clearer.
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 315.61 ms | 360.22 ms | 44.61 ms |
| 6edfca2 | 314.02 ms | 383.20 ms | 69.18 ms |
| d217708 | 375.27 ms | 415.68 ms | 40.41 ms |
| a5ab36f | 320.47 ms | 389.77 ms | 69.30 ms |
| d217708 | 355.34 ms | 381.39 ms | 26.05 ms |
| 319f256 | 317.53 ms | 370.83 ms | 53.29 ms |
| 6405ec5 | 310.88 ms | 354.56 ms | 43.69 ms |
| ce0a49e | 532.00 ms | 609.96 ms | 77.96 ms |
| dba088c | 365.46 ms | 366.31 ms | 0.85 ms |
| 889ecea | 367.58 ms | 437.52 ms | 69.94 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 6edfca2 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
| d217708 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| a5ab36f | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| d217708 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| 319f256 | 1.58 MiB | 2.19 MiB | 619.79 KiB |
| 6405ec5 | 1.58 MiB | 2.12 MiB | 552.23 KiB |
| ce0a49e | 1.58 MiB | 2.10 MiB | 532.94 KiB |
| dba088c | 1.58 MiB | 2.13 MiB | 558.99 KiB |
| 889ecea | 1.58 MiB | 2.11 MiB | 539.75 KiB |


Trailing or leading whitespace in the DSN string (commonly introduced by copy-paste from dashboards, wikis, or config tools) causes a
URISyntaxExceptionthat crashes the application on startup.This trims the DSN before passing it to the
URIconstructor inDsn.java.Fixes #5087