fix: Workaround FileNotFoundException on Android when recovering sessions #5084
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
FileNotFoundException from provider is never triggered in test - `test/Sentry.Tests/GlobalSessionManagerTests.cs:267-276`
The test TryRecoverPersistedSession_NoSessionFile_LogDebug sets _fixture.PersistedSessionProvider = _ => throw new FileNotFoundException() but this exception is never thrown. In GlobalSessionManager.TryRecoverPersistedSession(), line 154 checks _options.FileSystem.FileExists(filePath) before calling the provider. Since no session is started/persisted, FileExists returns false, the method returns early at line 157 with the debug message, and the provider is never invoked. The test passes coincidentally because the debug message matches, but it doesn't actually test exception handling from the provider.
Also found at:
src/Sentry/GlobalSessionManager.cs:204-206
Duration: 2m 28s · Tokens: 949.3k in / 11.5k out · Cost: $1.31 (+merge: $0.00)
Annotations
Check warning on line 276 in test/Sentry.Tests/GlobalSessionManagerTests.cs
sentry-warden / warden: find-bugs
FileNotFoundException from provider is never triggered in test
The test `TryRecoverPersistedSession_NoSessionFile_LogDebug` sets `_fixture.PersistedSessionProvider = _ => throw new FileNotFoundException()` but this exception is never thrown. In `GlobalSessionManager.TryRecoverPersistedSession()`, line 154 checks `_options.FileSystem.FileExists(filePath)` before calling the provider. Since no session is started/persisted, `FileExists` returns false, the method returns early at line 157 with the debug message, and the provider is never invoked. The test passes coincidentally because the debug message matches, but it doesn't actually test exception handling from the provider.
Check warning on line 206 in src/Sentry/GlobalSessionManager.cs
sentry-warden / warden: find-bugs
[5D5-YBF] FileNotFoundException from provider is never triggered in test (additional location)
The test `TryRecoverPersistedSession_NoSessionFile_LogDebug` sets `_fixture.PersistedSessionProvider = _ => throw new FileNotFoundException()` but this exception is never thrown. In `GlobalSessionManager.TryRecoverPersistedSession()`, line 154 checks `_options.FileSystem.FileExists(filePath)` before calling the provider. Since no session is started/persisted, `FileExists` returns false, the method returns early at line 157 with the debug message, and the provider is never invoked. The test passes coincidentally because the debug message matches, but it doesn't actually test exception handling from the provider.