Replace use of AssertionError in non-test code

PiperOrigin-RevId: 423324890
This commit is contained in:
olly 2022-01-21 16:05:54 +00:00 committed by Ian Baker
parent bfd227d354
commit f8de54e4a5
4 changed files with 17 additions and 29 deletions

View file

@ -2211,8 +2211,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
try {
MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000);
} catch (ExecutionException e) {
// It never happens because future.setException will not be called anywhere
throw new AssertionError(e);
// Never happens because future.setException will not be called.
throw new IllegalStateException(e);
} catch (TimeoutException 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.
@ -2247,10 +2247,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** Returns session interface if the controller can send the predefined command. */
@Nullable
IMediaSession getSessionInterfaceWithSessionCommandIfAble(@CommandCode int commandCode) {
if (commandCode == COMMAND_CODE_CUSTOM) {
throw new AssertionError(
"Use getSessionInterfaceWithSessionCommandIfAble(SessionCommand) for custom commands");
}
checkArgument(commandCode != COMMAND_CODE_CUSTOM);
if (!sessionCommands.contains(commandCode)) {
Log.w(TAG, "Controller isn't allowed to call command, commandCode=" + commandCode);
return null;
@ -2261,10 +2258,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
/** Returns session interface if the controller can send the custom command. */
@Nullable
IMediaSession getSessionInterfaceWithSessionCommandIfAble(SessionCommand command) {
if (command.commandCode != COMMAND_CODE_CUSTOM) {
throw new AssertionError(
"Use getSessionInterfaceWithSessionCommandIfAble(int) for predefined commands");
}
checkArgument(command.commandCode == COMMAND_CODE_CUSTOM);
if (!sessionCommands.contains(command)) {
Log.w(TAG, "Controller isn't allowed to call session command:" + command);
return null;

View file

@ -280,7 +280,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras);
break;
default:
throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type);
throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type);
}
pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS));
pendingSetMediaUriRequest = null;
@ -345,7 +345,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras);
break;
default:
throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type);
throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type);
}
pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS));
pendingSetMediaUriRequest = null;

View file

@ -292,12 +292,7 @@ import java.util.concurrent.Future;
if (result.resultCode == RESULT_SUCCESS) {
List<MediaItem> items = checkNotNull(result.value);
if (items.size() > pageSize) {
throw new AssertionError(
"The number of items must be less than or equal to the pageSize"
+ ", size="
+ items.size()
+ ", pageSize="
+ pageSize);
throw new IllegalStateException("Invalid size=" + items.size() + ", pageSize=" + pageSize);
}
}
}

View file

@ -646,7 +646,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return MediaDescriptionCompat.BT_FOLDER_TYPE_YEARS;
case MediaMetadata.FOLDER_TYPE_NONE:
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;
case Player.STATE_IDLE:
return PlaybackStateCompat.STATE_NONE;
case Player.STATE_READY:
case Player.STATE_ENDED:
return PlaybackStateCompat.STATE_PAUSED;
case Player.STATE_BUFFERING:
return playWhenReady
? PlaybackStateCompat.STATE_BUFFERING
: PlaybackStateCompat.STATE_PAUSED;
case Player.STATE_ENDED:
return PlaybackStateCompat.STATE_PAUSED;
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;
convertToCurrentPositionMs(playbackStateCompat, currentMediaMetadata, timeDiffMs);
return (currentPosition < duration) ? Player.STATE_READY : Player.STATE_ENDED;
default:
throw new AssertionError(
"PlaybackStateCompat.State shouldn't be " + playbackStateCompat.getState());
throw new IllegalStateException(
"Unrecognized PlaybackStateCompat: " + playbackStateCompat.getState());
}
}
@ -947,8 +946,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case PlaybackStateCompat.REPEAT_MODE_GROUP:
return Player.REPEAT_MODE_ALL;
default:
throw new AssertionError(
"PlaybackStateCompat repeat mode shouldn't be " + playbackStateCompatRepeatMode);
throw new IllegalArgumentException(
"Unrecognized PlaybackStateCompat.RepeatMode: " + playbackStateCompatRepeatMode);
}
}
@ -963,7 +962,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
case Player.REPEAT_MODE_ALL:
return PlaybackStateCompat.REPEAT_MODE_ALL;
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;
case PlaybackStateCompat.SHUFFLE_MODE_GROUP:
return true;
default:
throw new AssertionError(
"PlaybackStateCompat.ShuffleMode shouldn't be " + playbackStateCompatShuffleMode);
throw new IllegalArgumentException(
"Unrecognized ShuffleMode: " + playbackStateCompatShuffleMode);
}
}