nightscout / AndroidAPS

Opensource automated insulin delivery system (closed loop)
https://wiki.aaps.app
GNU Affero General Public License v3.0
691 stars 1.69k forks source link

[dev] ProfileSwitch dialog from Local Profile can crash if a wrong profil is in Local Profile list... #1488

Closed Philoul closed 2 years ago

Philoul commented 2 years ago

To reproduce this bug first create in Local profile plugin a new empty profile (+ button), but keep this profile "not valid" (LocalProfile1 is created with red background)

Then create one or several valid profiles after this "Wrong entry"

Because of one wrong profile included in profileStore, if you select the latest profile in Local Profile list and you click on "Activate Profile" button, AAPS will crash here (ProfileSwitchDialog.kt line 135) binding.profileList.setText(profileList[profileIndex as Int], false)

with this in Logcat

    java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
        at java.util.ArrayList.get(ArrayList.java:437)
        at info.nightscout.androidaps.dialogs.ProfileSwitchDialog.onViewCreated(ProfileSwitchDialog.kt:135)

I think it's because when you fill profileIndex list, the wrong profile is not added in profileIndex because of test line 125 (size of profileStore and size of profileIndex are different...)

            for (profileName in profileListToCheck) {
                val profileToCheck = activePlugin.activeProfileSource.profile?.getSpecificProfile(profileName.toString())
                if (profileToCheck != null && ProfileSealed.Pure(profileToCheck).isValid("ProfileSwitch", activePlugin.activePump, config, rh, rxBus, hardLimits, false).isValid)
                    profileList.add(profileName)
            }
MilosKozak commented 2 years ago

fixed by https://github.com/nightscout/AndroidAPS/commit/26c1652bba8fced140e4e708c3a03b92e90ae6ac good catch!