Fix nullness checks for addition of Cursor.getString stub

PiperOrigin-RevId: 377298145
This commit is contained in:
olly 2021-06-03 16:53:54 +01:00 committed by bachinger
parent b0a3bc5b28
commit 2b6581afe0
3 changed files with 14 additions and 8 deletions

View File

@ -15,12 +15,15 @@
*/
package com.google.android.exoplayer2.offline;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
@ -371,7 +374,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
}
/** Infers the MIME type from a v2 table row. */
private static String inferMimeType(String downloadType) {
private static String inferMimeType(@Nullable String downloadType) {
if ("dash".equals(downloadType)) {
return MimeTypes.APPLICATION_MPD;
} else if ("hls".equals(downloadType)) {
@ -441,8 +444,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID);
DownloadRequest request =
new DownloadRequest.Builder(
/* id= */ cursor.getString(COLUMN_INDEX_ID),
/* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)))
/* id= */ checkNotNull(cursor.getString(COLUMN_INDEX_ID)),
/* uri= */ Uri.parse(checkNotNull(cursor.getString(COLUMN_INDEX_URI))))
.setMimeType(cursor.getString(COLUMN_INDEX_MIME_TYPE))
.setStreamKeys(decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)))
.setKeySetId(keySetId.length > 0 ? keySetId : null)
@ -493,7 +496,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
*/
DownloadRequest request =
new DownloadRequest.Builder(
/* id= */ cursor.getString(0), /* uri= */ Uri.parse(cursor.getString(2)))
/* id= */ checkNotNull(cursor.getString(0)),
/* uri= */ Uri.parse(checkNotNull(cursor.getString(2))))
.setMimeType(inferMimeType(cursor.getString(1)))
.setStreamKeys(decodeStreamKeys(cursor.getString(3)))
.setCustomCacheKey(cursor.getString(4))
@ -519,9 +523,9 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
downloadProgress);
}
private static List<StreamKey> decodeStreamKeys(String encodedStreamKeys) {
private static List<StreamKey> decodeStreamKeys(@Nullable String encodedStreamKeys) {
ArrayList<StreamKey> streamKeys = new ArrayList<>();
if (encodedStreamKeys.isEmpty()) {
if (TextUtils.isEmpty(encodedStreamKeys)) {
return streamKeys;
}
String[] streamKeysStrings = Util.split(encodedStreamKeys, ",");

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.upstream.cache;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
@ -146,7 +148,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
try (Cursor cursor = getCursor()) {
Map<String, CacheFileMetadata> fileMetadata = new HashMap<>(cursor.getCount());
while (cursor.moveToNext()) {
String name = cursor.getString(COLUMN_INDEX_NAME);
String name = checkNotNull(cursor.getString(COLUMN_INDEX_NAME));
long length = cursor.getLong(COLUMN_INDEX_LENGTH);
long lastTouchTimestamp = cursor.getLong(COLUMN_INDEX_LAST_TOUCH_TIMESTAMP);
fileMetadata.put(name, new CacheFileMetadata(length, lastTouchTimestamp));

View File

@ -832,7 +832,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
try (Cursor cursor = getCursor()) {
while (cursor.moveToNext()) {
int id = cursor.getInt(COLUMN_INDEX_ID);
String key = cursor.getString(COLUMN_INDEX_KEY);
String key = checkNotNull(cursor.getString(COLUMN_INDEX_KEY));
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);