Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix(preferences): validate initial selection index in SingleChoicePre…
Browse files Browse the repository at this point in the history
…ference
  • Loading branch information
itsaky committed Nov 11, 2023
1 parent b140829 commit 8eddcc2
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.itsaky.androidide.preferences
import android.content.Context
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.IndexOutOfBoundsException

/**
* A preference which allows selecting a single value from a list of values.
Expand Down Expand Up @@ -56,6 +57,9 @@ abstract class SingleChoicePreference : ChoiceBasedDialogPreference(), Preferenc
) {

this.currentSelection = getInitiallySelectionItemPosition(preference.context)
if (currentSelection < 0 || currentSelection >= choices.size) {
throw IndexOutOfBoundsException("Initial selection: $currentSelection, size=${choices.size}")
}

dialog.setSingleChoiceItems(
choices,
Expand Down

0 comments on commit 8eddcc2

Please sign in to comment.