fix: crash in getSelectedDaysString from unsafe List-to-ArrayList cast#361
Open
MiMoHo wants to merge 1 commit into
Open
fix: crash in getSelectedDaysString from unsafe List-to-ArrayList cast#361MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change(s)
What changed and why
Context.getSelectedDaysString()builds its weekday list with an unsafe cast:Array.toList()returns a read-onlyListwhose concrete runtime type is not guaranteed to bejava.util.ArrayList— it depends on the Kotlin stdlib / build toolchain. Under a toolchain where it yields a different implementation (I hitjava.util.Arrays$ArrayListwith a JDK 21 / AGP build), theas ArrayList<String>cast throwsClassCastException, which crashes Fossify Clock on launch while binding an alarm row:Fix: construct the
ArrayListexplicitly.ArrayList(Collection)copies any collection and always yields ajava.util.ArrayList, somoveLastItemToFront()still applies and the produced string is unchanged — the fragile cast is simply removed.Tests performed
detekt,lintandassembleReleasepass locally on commons.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 noClassCastExceptionin 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
Coded with Opus 4.8 ultracode.