Commit f8de54e4 by olly Committed by Ian Baker

Replace use of AssertionError in non-test code

PiperOrigin-RevId: 423324890
parent bfd227d3
...@@ -2211,8 +2211,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -2211,8 +2211,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
try { try {
MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000); MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000);
} catch (ExecutionException e) { } catch (ExecutionException e) {
// It never happens because future.setException will not be called anywhere // Never happens because future.setException will not be called.
throw new AssertionError(e); throw new IllegalStateException(e);
} catch (TimeoutException e) { } catch (TimeoutException e) {
Log.w(TAG, "set/clearVideoSurface takes too long on the session side.", e); Log.w(TAG, "set/clearVideoSurface takes too long on the session side.", e);
// TODO(b/188888693): Let developers know the failure in their code. // TODO(b/188888693): Let developers know the failure in their code.
...@@ -2247,10 +2247,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -2247,10 +2247,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** Returns session interface if the controller can send the predefined command. */ /** Returns session interface if the controller can send the predefined command. */
@Nullable @Nullable
IMediaSession getSessionInterfaceWithSessionCommandIfAble(@CommandCode int commandCode) { IMediaSession getSessionInterfaceWithSessionCommandIfAble(@CommandCode int commandCode) {
if (commandCode == COMMAND_CODE_CUSTOM) { checkArgument(commandCode != COMMAND_CODE_CUSTOM);
throw new AssertionError(
"Use getSessionInterfaceWithSessionCommandIfAble(SessionCommand) for custom commands");
}
if (!sessionCommands.contains(commandCode)) { if (!sessionCommands.contains(commandCode)) {
Log.w(TAG, "Controller isn't allowed to call command, commandCode=" + commandCode); Log.w(TAG, "Controller isn't allowed to call command, commandCode=" + commandCode);
return null; return null;
...@@ -2261,10 +2258,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -2261,10 +2258,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** Returns session interface if the controller can send the custom command. */ /** Returns session interface if the controller can send the custom command. */
@Nullable @Nullable
IMediaSession getSessionInterfaceWithSessionCommandIfAble(SessionCommand command) { IMediaSession getSessionInterfaceWithSessionCommandIfAble(SessionCommand command) {
if (command.commandCode != COMMAND_CODE_CUSTOM) { checkArgument(command.commandCode == COMMAND_CODE_CUSTOM);
throw new AssertionError(
"Use getSessionInterfaceWithSessionCommandIfAble(int) for predefined commands");
}
if (!sessionCommands.contains(command)) { if (!sessionCommands.contains(command)) {
Log.w(TAG, "Controller isn't allowed to call session command:" + command); Log.w(TAG, "Controller isn't allowed to call session command:" + command);
return null; return null;
......
...@@ -280,7 +280,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -280,7 +280,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras); Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras);
break; break;
default: default:
throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type); throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type);
} }
pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS)); pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS));
pendingSetMediaUriRequest = null; pendingSetMediaUriRequest = null;
...@@ -345,7 +345,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -345,7 +345,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras); Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras);
break; break;
default: default:
throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type); throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type);
} }
pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS)); pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS));
pendingSetMediaUriRequest = null; pendingSetMediaUriRequest = null;
......
...@@ -292,12 +292,7 @@ import java.util.concurrent.Future; ...@@ -292,12 +292,7 @@ import java.util.concurrent.Future;
if (result.resultCode == RESULT_SUCCESS) { if (result.resultCode == RESULT_SUCCESS) {
List<MediaItem> items = checkNotNull(result.value); List<MediaItem> items = checkNotNull(result.value);
if (items.size() > pageSize) { if (items.size() > pageSize) {
throw new AssertionError( throw new IllegalStateException("Invalid size=" + items.size() + ", pageSize=" + pageSize);
"The number of items must be less than or equal to the pageSize"
+ ", size="
+ items.size()
+ ", pageSize="
+ pageSize);
} }
} }
} }
......
...@@ -646,7 +646,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -646,7 +646,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return MediaDescriptionCompat.BT_FOLDER_TYPE_YEARS; return MediaDescriptionCompat.BT_FOLDER_TYPE_YEARS;
case MediaMetadata.FOLDER_TYPE_NONE: case MediaMetadata.FOLDER_TYPE_NONE:
default: default:
throw new AssertionError("Unsupported folder type " + folderType); throw new IllegalArgumentException("Unrecognized FolderType: " + folderType);
} }
} }
...@@ -743,15 +743,14 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -743,15 +743,14 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case Player.STATE_IDLE: case Player.STATE_IDLE:
return PlaybackStateCompat.STATE_NONE; return PlaybackStateCompat.STATE_NONE;
case Player.STATE_READY: case Player.STATE_READY:
case Player.STATE_ENDED:
return PlaybackStateCompat.STATE_PAUSED; return PlaybackStateCompat.STATE_PAUSED;
case Player.STATE_BUFFERING: case Player.STATE_BUFFERING:
return playWhenReady return playWhenReady
? PlaybackStateCompat.STATE_BUFFERING ? PlaybackStateCompat.STATE_BUFFERING
: PlaybackStateCompat.STATE_PAUSED; : PlaybackStateCompat.STATE_PAUSED;
case Player.STATE_ENDED:
return PlaybackStateCompat.STATE_PAUSED;
default: default:
throw new AssertionError("Playback state shouldn't be " + playbackState); throw new IllegalArgumentException("Unrecognized State: " + playbackState);
} }
} }
...@@ -820,8 +819,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -820,8 +819,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
convertToCurrentPositionMs(playbackStateCompat, currentMediaMetadata, timeDiffMs); convertToCurrentPositionMs(playbackStateCompat, currentMediaMetadata, timeDiffMs);
return (currentPosition < duration) ? Player.STATE_READY : Player.STATE_ENDED; return (currentPosition < duration) ? Player.STATE_READY : Player.STATE_ENDED;
default: default:
throw new AssertionError( throw new IllegalStateException(
"PlaybackStateCompat.State shouldn't be " + playbackStateCompat.getState()); "Unrecognized PlaybackStateCompat: " + playbackStateCompat.getState());
} }
} }
...@@ -947,8 +946,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -947,8 +946,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case PlaybackStateCompat.REPEAT_MODE_GROUP: case PlaybackStateCompat.REPEAT_MODE_GROUP:
return Player.REPEAT_MODE_ALL; return Player.REPEAT_MODE_ALL;
default: default:
throw new AssertionError( throw new IllegalArgumentException(
"PlaybackStateCompat repeat mode shouldn't be " + playbackStateCompatRepeatMode); "Unrecognized PlaybackStateCompat.RepeatMode: " + playbackStateCompatRepeatMode);
} }
} }
...@@ -963,7 +962,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -963,7 +962,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case Player.REPEAT_MODE_ALL: case Player.REPEAT_MODE_ALL:
return PlaybackStateCompat.REPEAT_MODE_ALL; return PlaybackStateCompat.REPEAT_MODE_ALL;
default: default:
throw new AssertionError("Player.RepeatMode shouldn't be " + repeatMode); throw new IllegalArgumentException("Unrecognized RepeatMode: " + repeatMode);
} }
} }
...@@ -978,8 +977,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -978,8 +977,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case PlaybackStateCompat.SHUFFLE_MODE_GROUP: case PlaybackStateCompat.SHUFFLE_MODE_GROUP:
return true; return true;
default: default:
throw new AssertionError( throw new IllegalArgumentException(
"PlaybackStateCompat.ShuffleMode shouldn't be " + playbackStateCompatShuffleMode); "Unrecognized ShuffleMode: " + playbackStateCompatShuffleMode);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment