Skip to content

Commit

Permalink
log a warning if index gets out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Nov 12, 2024
1 parent d481541 commit a5167f3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;

import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -47,6 +49,8 @@
import org.thoughtcrime.securesms.util.views.Stub;

public class ViewUtil {
private final static String TAG = ViewUtil.class.getSimpleName();

@SuppressWarnings("deprecation")
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
v.setBackground(drawable);
Expand Down Expand Up @@ -274,6 +278,7 @@ public static int getStatusBarHeight(@NonNull View view) {
// Otherwise, to avoid ArrayIndexOutOfBoundsException, 0 is returned, assuming to refer to a good default.
public static int checkBounds(int selection, AbsSpinner view) {
if (selection < 0 || selection >= view.getCount()) {
Log.w(TAG, "index " + selection + " out of bounds of " + view.toString());
return 0;
}
return selection;
Expand Down

0 comments on commit a5167f3

Please sign in to comment.