From 55f50e24eb4f1196d5bd38973265948a69e7aaf0 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 24 May 2021 16:11:06 +0100 Subject: [PATCH] Defensively copy potentially mutable text in Cue constructor Without this the Cue isn't deeply immutable, which can be a bit surprising. PiperOrigin-RevId: 375477571 --- .../java/com/google/android/exoplayer2/text/Cue.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java b/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java index 46f865782f..7735b808de 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/text/Cue.java @@ -19,6 +19,8 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.text.Layout; import android.text.Layout.Alignment; +import android.text.Spanned; +import android.text.SpannedString; import androidx.annotation.ColorInt; import androidx.annotation.IntDef; import androidx.annotation.Nullable; @@ -458,7 +460,13 @@ public final class Cue { } else { Assertions.checkArgument(bitmap == null); } - this.text = text; + if (text instanceof Spanned) { + this.text = SpannedString.valueOf(text); + } else if (text != null) { + this.text = text.toString(); + } else { + this.text = null; + } this.textAlignment = textAlignment; this.multiRowAlignment = multiRowAlignment; this.bitmap = bitmap;