Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8b1fcfc4
authored
Jul 07, 2021
by
aquilescanta
Committed by
kim-vde
Jul 09, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Drop support for subclass instance unbundling in PlaybackException
PiperOrigin-RevId: 383408075
parent
54b4f663
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
55 deletions
library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java
library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java
library/common/src/test/java/com/google/android/exoplayer2/PlaybackExceptionTest.java
library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java
View file @
8b1fcfc4
...
@@ -27,7 +27,6 @@ import com.google.android.exoplayer2.util.Util;
...
@@ -27,7 +27,6 @@ import com.google.android.exoplayer2.util.Util;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.reflect.Field
;
/** Thrown when a non locally recoverable playback failure occurs. */
/** Thrown when a non locally recoverable playback failure occurs. */
public
class
PlaybackException
extends
Exception
implements
Bundleable
{
public
class
PlaybackException
extends
Exception
implements
Bundleable
{
...
@@ -382,7 +381,6 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -382,7 +381,6 @@ public class PlaybackException extends Exception implements Bundleable {
@IntDef
(
@IntDef
(
open
=
true
,
open
=
true
,
value
=
{
value
=
{
FIELD_STRING_CLASS_NAME
,
FIELD_INT_ERROR_CODE
,
FIELD_INT_ERROR_CODE
,
FIELD_LONG_TIMESTAMP_MS
,
FIELD_LONG_TIMESTAMP_MS
,
FIELD_STRING_MESSAGE
,
FIELD_STRING_MESSAGE
,
...
@@ -391,12 +389,11 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -391,12 +389,11 @@ public class PlaybackException extends Exception implements Bundleable {
})
})
protected
@interface
FieldNumber
{}
protected
@interface
FieldNumber
{}
private
static
final
int
FIELD_STRING_CLASS_NAME
=
0
;
private
static
final
int
FIELD_INT_ERROR_CODE
=
0
;
private
static
final
int
FIELD_INT_ERROR_CODE
=
1
;
private
static
final
int
FIELD_LONG_TIMESTAMP_MS
=
1
;
private
static
final
int
FIELD_LONG_TIMESTAMP_MS
=
2
;
private
static
final
int
FIELD_STRING_MESSAGE
=
2
;
private
static
final
int
FIELD_STRING_MESSAGE
=
3
;
private
static
final
int
FIELD_STRING_CAUSE_CLASS_NAME
=
3
;
private
static
final
int
FIELD_STRING_CAUSE_CLASS_NAME
=
4
;
private
static
final
int
FIELD_STRING_CAUSE_MESSAGE
=
4
;
private
static
final
int
FIELD_STRING_CAUSE_MESSAGE
=
5
;
/**
/**
* Defines a minimum field id value for subclasses to use when implementing {@link #toBundle()}
* Defines a minimum field id value for subclasses to use when implementing {@link #toBundle()}
...
@@ -409,32 +406,12 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -409,32 +406,12 @@ public class PlaybackException extends Exception implements Bundleable {
/** Object that can create a {@link PlaybackException} from a {@link Bundle}. */
/** Object that can create a {@link PlaybackException} from a {@link Bundle}. */
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
final
Creator
<
PlaybackException
>
CREATOR
=
public
static
final
Creator
<
PlaybackException
>
CREATOR
=
PlaybackException:
:
new
;
bundle
->
{
String
className
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_CLASS_NAME
));
if
(
className
!=
null
&&
!
PlaybackException
.
class
.
getName
().
equals
(
className
))
{
try
{
Field
creatorField
=
Class
.
forName
(
className
).
getField
(
"CREATOR"
);
// It is ok to pass null to Field.get for static fields.
@SuppressWarnings
(
"nullness:argument"
)
Creator
<
PlaybackException
>
creator
=
(
Creator
<
PlaybackException
>)
creatorField
.
get
(
/* obj= */
null
);
if
(
creator
!=
null
)
{
return
creator
.
fromBundle
(
bundle
);
}
}
catch
(
Throwable
e
)
{
// Failed to create an instance using the creator from the class with the given name.
// Fall through and try to deserialize the PlaybackException fields only.
}
}
return
new
PlaybackException
(
bundle
);
};
@CallSuper
@CallSuper
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
keyForField
(
FIELD_STRING_CLASS_NAME
),
getClass
().
getName
());
bundle
.
putInt
(
keyForField
(
FIELD_INT_ERROR_CODE
),
errorCode
);
bundle
.
putInt
(
keyForField
(
FIELD_INT_ERROR_CODE
),
errorCode
);
bundle
.
putLong
(
keyForField
(
FIELD_LONG_TIMESTAMP_MS
),
timestampMs
);
bundle
.
putLong
(
keyForField
(
FIELD_LONG_TIMESTAMP_MS
),
timestampMs
);
bundle
.
putString
(
keyForField
(
FIELD_STRING_MESSAGE
),
getMessage
());
bundle
.
putString
(
keyForField
(
FIELD_STRING_MESSAGE
),
getMessage
());
...
...
library/common/src/test/java/com/google/android/exoplayer2/ExoPlaybackExceptionTest.java
View file @
8b1fcfc4
...
@@ -35,14 +35,6 @@ public class ExoPlaybackExceptionTest {
...
@@ -35,14 +35,6 @@ public class ExoPlaybackExceptionTest {
}
}
@Test
@Test
public
void
roundTripViaBundle_usingPlaybackExceptionCreator_yieldsEqualInstance
()
{
ExoPlaybackException
before
=
ExoPlaybackException
.
createForRemote
(
/* message= */
"test"
);
ExoPlaybackException
after
=
(
ExoPlaybackException
)
PlaybackException
.
CREATOR
.
fromBundle
(
before
.
toBundle
());
assertThat
(
areExoPlaybackExceptionsEqual
(
before
,
after
)).
isTrue
();
}
@Test
public
void
roundTripViaBundle_ofExoPlaybackExceptionTypeRenderer_yieldsEqualInstance
()
{
public
void
roundTripViaBundle_ofExoPlaybackExceptionTypeRenderer_yieldsEqualInstance
()
{
ExoPlaybackException
before
=
ExoPlaybackException
before
=
ExoPlaybackException
.
createForRenderer
(
ExoPlaybackException
.
createForRenderer
(
...
...
library/common/src/test/java/com/google/android/exoplayer2/PlaybackExceptionTest.java
View file @
8b1fcfc4
...
@@ -54,13 +54,11 @@ public class PlaybackExceptionTest {
...
@@ -54,13 +54,11 @@ public class PlaybackExceptionTest {
/* timestampMs= */
1000
);
/* timestampMs= */
1000
);
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
// We purposefully omit the class name to test that PlaybackException fields are deserialized,
bundle
.
putInt
(
"0"
,
5001
);
// Error code
// even though it was not possible to create an instance using the class name in the bundle.
bundle
.
putLong
(
"1"
,
1000
);
// Timestamp.
bundle
.
putInt
(
"1"
,
5001
);
// Error code
bundle
.
putString
(
"2"
,
"message"
);
bundle
.
putLong
(
"2"
,
1000
);
// Timestamp.
bundle
.
putString
(
"3"
,
expectedCause
.
getClass
().
getName
());
bundle
.
putString
(
"3"
,
"message"
);
bundle
.
putString
(
"4"
,
"cause message"
);
bundle
.
putString
(
"4"
,
expectedCause
.
getClass
().
getName
());
bundle
.
putString
(
"5"
,
"cause message"
);
assertPlaybackExceptionsAreEquivalent
(
assertPlaybackExceptionsAreEquivalent
(
expectedException
,
PlaybackException
.
CREATOR
.
fromBundle
(
bundle
));
expectedException
,
PlaybackException
.
CREATOR
.
fromBundle
(
bundle
));
...
@@ -77,12 +75,11 @@ public class PlaybackExceptionTest {
...
@@ -77,12 +75,11 @@ public class PlaybackExceptionTest {
/* timestampMs= */
2000
);
/* timestampMs= */
2000
);
Bundle
bundle
=
exception
.
toBundle
();
Bundle
bundle
=
exception
.
toBundle
();
assertThat
(
bundle
.
getString
(
"0"
)).
isEqualTo
(
PlaybackException
.
class
.
getName
());
assertThat
(
bundle
.
getInt
(
"0"
)).
isEqualTo
(
4003
);
// Error code.
assertThat
(
bundle
.
getInt
(
"1"
)).
isEqualTo
(
4003
);
// Error code.
assertThat
(
bundle
.
getLong
(
"1"
)).
isEqualTo
(
2000
);
// Timestamp.
assertThat
(
bundle
.
getLong
(
"2"
)).
isEqualTo
(
2000
);
// Timestamp.
assertThat
(
bundle
.
getString
(
"2"
)).
isEqualTo
(
"message"
);
assertThat
(
bundle
.
getString
(
"3"
)).
isEqualTo
(
"message"
);
assertThat
(
bundle
.
getString
(
"3"
)).
isEqualTo
(
cause
.
getClass
().
getName
());
assertThat
(
bundle
.
getString
(
"4"
)).
isEqualTo
(
cause
.
getClass
().
getName
());
assertThat
(
bundle
.
getString
(
"4"
)).
isEqualTo
(
"cause message"
);
assertThat
(
bundle
.
getString
(
"5"
)).
isEqualTo
(
"cause message"
);
}
}
@Test
@Test
...
@@ -96,11 +93,11 @@ public class PlaybackExceptionTest {
...
@@ -96,11 +93,11 @@ public class PlaybackExceptionTest {
/* timestampMs= */
1000
);
/* timestampMs= */
1000
);
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putInt
(
"
1
"
,
5001
);
// Error code
bundle
.
putInt
(
"
0
"
,
5001
);
// Error code
bundle
.
putLong
(
"
2
"
,
1000
);
// Timestamp.
bundle
.
putLong
(
"
1
"
,
1000
);
// Timestamp.
bundle
.
putString
(
"
3
"
,
"message"
);
bundle
.
putString
(
"
2
"
,
"message"
);
bundle
.
putString
(
"
4
"
,
"invalid cause class name"
);
bundle
.
putString
(
"
3
"
,
"invalid cause class name"
);
bundle
.
putString
(
"
5
"
,
"cause message"
);
bundle
.
putString
(
"
4
"
,
"cause message"
);
assertPlaybackExceptionsAreEquivalent
(
assertPlaybackExceptionsAreEquivalent
(
expectedException
,
PlaybackException
.
CREATOR
.
fromBundle
(
bundle
));
expectedException
,
PlaybackException
.
CREATOR
.
fromBundle
(
bundle
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment