From f9032a58939cd31068c1e686d821eb404b652cd7 Mon Sep 17 00:00:00 2001 From: ibaker Date: Fri, 8 Mar 2024 05:56:16 -0800 Subject: [PATCH] Add `checkNotNull(uri)` to `DataSpec` constructor This check is already present in `DataSpec.Builder.build()` but there are many public constructors which bypass the builder (only some of which are deprecated), so this adds an additional check. PiperOrigin-RevId: 613908358 --- RELEASENOTES.md | 2 ++ .../src/main/java/androidx/media3/datasource/DataSpec.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 1d5bdebba4..a1aea6e215 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -57,6 +57,8 @@ where `package` is different to the package of the current application. This wasn't previously documented to work, but is a more efficient way of accessing resources in another package than by name. + * Eagerly check `url` is non-null in the `DataSpec` constructors. This + parameter was already annotated to be non-null. * Effect: * Improved PQ to SDR tone-mapping by converting color spaces. * Support multiple speed changes within the same `EditedMediaItem` or diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/DataSpec.java b/libraries/datasource/src/main/java/androidx/media3/datasource/DataSpec.java index 2da5d6a095..dea5284fb3 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/DataSpec.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/DataSpec.java @@ -15,6 +15,7 @@ */ package androidx.media3.datasource; +import static androidx.media3.common.util.Assertions.checkNotNull; import static java.lang.annotation.ElementType.TYPE_USE; import android.net.Uri; @@ -473,7 +474,7 @@ public final class DataSpec { Assertions.checkArgument(uriPositionOffset + position >= 0); Assertions.checkArgument(position >= 0); Assertions.checkArgument(length > 0 || length == C.LENGTH_UNSET); - this.uri = uri; + this.uri = checkNotNull(uri); this.uriPositionOffset = uriPositionOffset; this.httpMethod = httpMethod; this.httpBody = httpBody != null && httpBody.length != 0 ? httpBody : null;