Mark assertion methods as @Pure
See https://checkerframework.org/manual/#type-refinement-purity. PiperOrigin-RevId: 344994705
This commit is contained in:
parent
69dad31b67
commit
c7e1d3f222
@ -20,6 +20,7 @@ import android.text.TextUtils;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
||||||
|
import org.checkerframework.dataflow.qual.Pure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods for asserting the truth of expressions and properties.
|
* Provides methods for asserting the truth of expressions and properties.
|
||||||
@ -34,6 +35,7 @@ public final class Assertions {
|
|||||||
* @param expression The expression to evaluate.
|
* @param expression The expression to evaluate.
|
||||||
* @throws IllegalArgumentException If {@code expression} is false.
|
* @throws IllegalArgumentException If {@code expression} is false.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static void checkArgument(boolean expression) {
|
public static void checkArgument(boolean expression) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@ -48,6 +50,7 @@ public final class Assertions {
|
|||||||
* to a {@link String} using {@link String#valueOf(Object)}.
|
* to a {@link String} using {@link String#valueOf(Object)}.
|
||||||
* @throws IllegalArgumentException If {@code expression} is false.
|
* @throws IllegalArgumentException If {@code expression} is false.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static void checkArgument(boolean expression, Object errorMessage) {
|
public static void checkArgument(boolean expression, Object errorMessage) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
||||||
throw new IllegalArgumentException(String.valueOf(errorMessage));
|
throw new IllegalArgumentException(String.valueOf(errorMessage));
|
||||||
@ -63,6 +66,7 @@ public final class Assertions {
|
|||||||
* @return The {@code index} that was validated.
|
* @return The {@code index} that was validated.
|
||||||
* @throws IndexOutOfBoundsException If {@code index} falls outside the specified bounds.
|
* @throws IndexOutOfBoundsException If {@code index} falls outside the specified bounds.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static int checkIndex(int index, int start, int limit) {
|
public static int checkIndex(int index, int start, int limit) {
|
||||||
if (index < start || index >= limit) {
|
if (index < start || index >= limit) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
@ -76,6 +80,7 @@ public final class Assertions {
|
|||||||
* @param expression The expression to evaluate.
|
* @param expression The expression to evaluate.
|
||||||
* @throws IllegalStateException If {@code expression} is false.
|
* @throws IllegalStateException If {@code expression} is false.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static void checkState(boolean expression) {
|
public static void checkState(boolean expression) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@ -90,6 +95,7 @@ public final class Assertions {
|
|||||||
* to a {@link String} using {@link String#valueOf(Object)}.
|
* to a {@link String} using {@link String#valueOf(Object)}.
|
||||||
* @throws IllegalStateException If {@code expression} is false.
|
* @throws IllegalStateException If {@code expression} is false.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static void checkState(boolean expression, Object errorMessage) {
|
public static void checkState(boolean expression, Object errorMessage) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) {
|
||||||
throw new IllegalStateException(String.valueOf(errorMessage));
|
throw new IllegalStateException(String.valueOf(errorMessage));
|
||||||
@ -106,6 +112,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static <T> T checkStateNotNull(@Nullable T reference) {
|
public static <T> T checkStateNotNull(@Nullable T reference) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@ -125,6 +132,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage) {
|
public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
||||||
throw new IllegalStateException(String.valueOf(errorMessage));
|
throw new IllegalStateException(String.valueOf(errorMessage));
|
||||||
@ -142,6 +150,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static <T> T checkNotNull(@Nullable T reference) {
|
public static <T> T checkNotNull(@Nullable T reference) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
@ -161,6 +170,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static <T> T checkNotNull(@Nullable T reference, Object errorMessage) {
|
public static <T> T checkNotNull(@Nullable T reference, Object errorMessage) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
|
||||||
throw new NullPointerException(String.valueOf(errorMessage));
|
throw new NullPointerException(String.valueOf(errorMessage));
|
||||||
@ -177,6 +187,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static String checkNotEmpty(@Nullable String string) {
|
public static String checkNotEmpty(@Nullable String string) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@ -195,6 +206,7 @@ public final class Assertions {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
|
||||||
@EnsuresNonNull({"#1"})
|
@EnsuresNonNull({"#1"})
|
||||||
|
@Pure
|
||||||
public static String checkNotEmpty(@Nullable String string, Object errorMessage) {
|
public static String checkNotEmpty(@Nullable String string, Object errorMessage) {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) {
|
||||||
throw new IllegalArgumentException(String.valueOf(errorMessage));
|
throw new IllegalArgumentException(String.valueOf(errorMessage));
|
||||||
@ -208,6 +220,7 @@ public final class Assertions {
|
|||||||
*
|
*
|
||||||
* @throws IllegalStateException If the calling thread is not the application's main thread.
|
* @throws IllegalStateException If the calling thread is not the application's main thread.
|
||||||
*/
|
*/
|
||||||
|
@Pure
|
||||||
public static void checkMainThread() {
|
public static void checkMainThread() {
|
||||||
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && Looper.myLooper() != Looper.getMainLooper()) {
|
if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && Looper.myLooper() != Looper.getMainLooper()) {
|
||||||
throw new IllegalStateException("Not in applications main thread");
|
throw new IllegalStateException("Not in applications main thread");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user