music: tolerate untagged rows in the MediaStore scan
- Commit
078b364565857792d18122b82886424a5d75c34d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:15 UTC (28 days ago)
- Parents
fe946ba
Symptom: a file with no title/artist/album tags could crash the library scan (or a later title search/sort), because the cursor's nullable strings were stored straight into Music's non-null fields. Root cause: Cursor.getString returns null for missing tags, but readSong and the album query in getAlbums passed the result through unchecked. getArtists already documents and normalises exactly this MediaStore behaviour (null, blank, the unknown sentinel); the song and album queries did not. Fix: normalise null title/artist/album to empty strings at the scan boundary, the same place getArtists normalises artist names, so no consumer has to defend against a null that the type says cannot occur. Verification: compile plus module unit tests after this series.
Diff
music/src/main/java/com/vayunmathur/music/platform/Util.kt
diff --git a/music/src/main/java/com/vayunmathur/music/platform/Util.kt b/music/src/main/java/com/vayunmathur/music/platform/Util.ktindex 116faf91ac..7ab46f0359 100644--- a/music/src/main/java/com/vayunmathur/music/platform/Util.kt+++ b/music/src/main/java/com/vayunmathur/music/platform/Util.kt@@ -170,10 +170,14 @@ private fun readSong(cursor: android.database.Cursor, columns: SongColumns): Mus val (discNumber, trackNumber) = splitDiscTrack(cursor.getInt(columns.track)) return Music( id = id,- title = cursor.getString(columns.title),- artist = cursor.getString(columns.artist),+ // MediaStore returns null for untagged files; Music's fields are+ // non-null and consumers sort/search on them directly, so an+ // untagged row crashed the scan or a later search. getArtists+ // already normalises the same case; do it here too.+ title = cursor.getString(columns.title) ?: "",+ artist = cursor.getString(columns.artist) ?: "", artistId = cursor.getLong(columns.artistId),- album = cursor.getString(columns.album),+ album = cursor.getString(columns.album) ?: "", albumId = cursor.getLong(columns.albumId), uri = uri, duration = cursor.getLong(columns.duration),@@ -215,7 +219,7 @@ suspend fun getAlbums(context: Context): List<Album> = withContext(Dispatchers.I while (cursor.moveToNext()) { val id = cursor.getLong(idColumn)- val title = cursor.getString(titleColumn)+ val title = cursor.getString(titleColumn) ?: "" val contentUri = ContentUris.withAppendedId( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id