Fix StorageException for users with multi-path offline content - #295
Open
ziad-halabi9 wants to merge 1 commit into
Open
Fix StorageException for users with multi-path offline content#295ziad-halabi9 wants to merge 1 commit into
ziad-halabi9 wants to merge 1 commit into
Conversation
The helper cached a single factory per storage type (internal/external), ignoring the path argument after the first call. Because the helper is @reusable in Dagger, the stale factory persisted for the app's lifetime, so users with offline content at multiple paths within one storage class hit StorageException / ERROR_CODE_IO_UNSPECIFIED on later tracks whose path didn't match the first-seen one. Switch the per-storage-type field to a path-keyed map so each distinct path gets its own factory. Replace !! with checkNotNull on the nullable provider while we're here. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
michpohl
reviewed
May 4, 2026
Contributor
There was a problem hiding this comment.
nit: I'd love if we could use more descriptive naming and given/when/then in the tests, to make them more clear, something like:
@Test
fun `getExternal returns same instance when called multiple times with same path`() {
// given
val cacheA = mock<Cache>()
whenever(offlineCacheProvider.getExternal("a")).thenReturn(cacheA)
// when
val firstA = helper.getExternal("a")
val secondA = helper.getExternal("a")
// then
assertThat(secondA).isSameInstanceAs(firstA)
...
}
michpohl
approved these changes
May 4, 2026
michpohl
left a comment
Contributor
There was a problem hiding this comment.
Approving with 1 comment. I leave it up to you if you want to change or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OfflineDataSourceFactoryHelper.getExternal/getInternalcached one factory per storage type and ignored thepathargument after the first call. Because the helper is@Reusablein Dagger, that stale factory persisted for the whole app session, so users whose offline content lived at multiple paths within one storage class (e.g. they switched download location, hit an OS-level path migration, or use a different SD-card root) hitStorageException/ERROR_CODE_IO_UNSPECIFIEDon later tracks at any path other than the first-seen one.Map<String, T>so each distinct path memoizes its own factory. Replace!!withcheckNotNullon the nullable provider.OfflineDataSourceFactoryHelperTest(5 cases): per-path memoization for bothgetExternalandgetInternal, independence of internal/external maps, andIllegalStateExceptionwhen the provider is null.Test plan
./gradlew :player:playback-engine:testDebugUnitTest(full module suite passes locally on JBR 21)OfflineDataSourceFactoryHelperTest— all 5 cases pass🤖 Generated with Claude Code