Skip to content

fix: crash in getSelectedDaysString from unsafe List-to-ArrayList cast#361

Open
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/getselecteddays-unsafe-cast
Open

fix: crash in getSelectedDaysString from unsafe List-to-ArrayList cast#361
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/getselecteddays-unsafe-cast

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 4, 2026

Copy link
Copy Markdown

Type of change(s)

  • Bug fix

What changed and why

Context.getSelectedDaysString() builds its weekday list with an unsafe cast:

val weekDays = resources.getStringArray(R.array.week_days_short).toList() as ArrayList<String>

Array.toList() returns a read-only List whose concrete runtime type is not guaranteed to be java.util.ArrayList — it depends on the Kotlin stdlib / build toolchain. Under a toolchain where it yields a different implementation (I hit java.util.Arrays$ArrayList with a JDK 21 / AGP build), the as ArrayList<String> cast throws ClassCastException, which crashes Fossify Clock on launch while binding an alarm row:

java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
    at org.fossify.commons.extensions.ContextKt.getSelectedDaysString(Context.kt:636)
    at org.fossify.clock.adapters.AlarmsAdapter.getAlarmSelectedDaysString(AlarmsAdapter.kt:206)

Fix: construct the ArrayList explicitly. ArrayList(Collection) copies any collection and always yields a java.util.ArrayList, so moveLastItemToFront() still applies and the produced string is unchanged — the fragile cast is simply removed.

Tests performed

  • detekt, lint and assembleRelease pass locally on commons.
  • Reproduced + fixed on-device: built Fossify Clock against a local commons via includeBuild. Before the fix, Clock crashed 3/3 on launch with the stack above. After the fix, the Alarm tab renders correctly (7:00 am — Mon, Tue, Wed, Thu, Fri, 9:00 am — Sun, Sat) with no ClassCastException in logcat.

Note on issue-first

This is a crash I hit while testing rather than a pre-filed issue; submitting under the "critical, production-blocking bug" exception in the guidelines. Happy to open a tracking issue first if you'd prefer.

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator.
  • I have self-reviewed my pull request.
  • I understand every change in this pull request.

Coded with Opus 4.8 ultracode.

…st cast

resources.getStringArray(...).toList() returns a read-only List whose
concrete runtime type is not guaranteed to be java.util.ArrayList. The
`as ArrayList<String>` cast throws ClassCastException under build
toolchains where toList() yields a different List implementation (e.g.
java.util.Arrays$ArrayList), which crashes the alarm list in Fossify
Clock (AlarmsAdapter -> getSelectedDaysString) on launch.

Construct an ArrayList explicitly instead; its constructor copies any
Collection and always yields a java.util.ArrayList, so moveLastItemToFront()
still applies and the output is unchanged.
@MiMoHo MiMoHo requested a review from naveensingh as a code owner July 4, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant