Skip to content

Generate predefined names at runtime/startup

4a7a2ec
Select commit
Loading
Failed to load commit list.
Open

perf: avoid MeasurementUnit enum boxing allocations #5218

Generate predefined names at runtime/startup
4a7a2ec
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed May 11, 2026 in 3m 29s

1 issue

find-bugs: Found 1 issue (1 high)

High

GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output - `src/Sentry/MeasurementUnit.cs:22-26`

The new implementation uses Enum.GetNames<Duration>() (etc.) to precompute names, but Enum.GetNames<T>() returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used _unit.ToString().ToLowerInvariant() which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via ToString()/ToNullableString(). The PR claims tests pass, but CanUseDurationUnits, CanUseInformationUnits, and CanUseFractionUnits would all fail with this code.

Also found at:

  • src/Sentry/MeasurementUnit.cs:109-111

⏱ 1m 5s · 249.3k in / 4.3k out · $1.49 (+verification: $1.09, +merge: $0.00)

Annotations

Check failure on line 26 in src/Sentry/MeasurementUnit.cs

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output

The new implementation uses `Enum.GetNames<Duration>()` (etc.) to precompute names, but `Enum.GetNames<T>()` returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used `_unit.ToString().ToLowerInvariant()` which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via `ToString()`/`ToNullableString()`. The PR claims tests pass, but `CanUseDurationUnits`, `CanUseInformationUnits`, and `CanUseFractionUnits` would all fail with this code.

Check failure on line 111 in src/Sentry/MeasurementUnit.cs

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

[9AB-NUT] GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output (additional location)

The new implementation uses `Enum.GetNames<Duration>()` (etc.) to precompute names, but `Enum.GetNames<T>()` returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used `_unit.ToString().ToLowerInvariant()` which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via `ToString()`/`ToNullableString()`. The PR claims tests pass, but `CanUseDurationUnits`, `CanUseInformationUnits`, and `CanUseFractionUnits` would all fail with this code.