Modern Apps git

← Modern-Apps.git

education: guard drag-match answer lookup against malformed packs

Commit
700e7b776d6663d1caa9bd108639ac5aa2d92fb4
Author
Vayun Mathur <[email protected]>
When
2026-11-19 01:57 UTC (17 days ago)
Parents
1e279c2
K2DragMatch indexed correctRightForLeft with a left-side target
index. A matching question whose answer list is shorter than its
left list (a malformed content pack: ContentValidator only runs in
CI, ContentRepository.load does not validate at runtime) threw
IndexOutOfBoundsException the first time a child dropped a chip on
a target past the end of the answer list, crashing the K-2 quiz.

Use getOrNull so a mismatched entry simply never matches and the
chip springs back, like a wrong drop.

Verified: ./gradlew :education:testDevUnitTest (pass),
./check education (pass).

Diff

education/src/main/java/com/vayunmathur/education/ui/K2DragMatch.kt
diff --git a/education/src/main/java/com/vayunmathur/education/ui/K2DragMatch.kt b/education/src/main/java/com/vayunmathur/education/ui/K2DragMatch.ktindex fa09d7bc4f..129c6ef2e3 100644--- a/education/src/main/java/com/vayunmathur/education/ui/K2DragMatch.kt+++ b/education/src/main/java/com/vayunmathur/education/ui/K2DragMatch.kt@@ -116,7 +116,7 @@ fun K2DragMatch(question: MatchingQuestion, enabled: Boolean, onSolved: () -> Un                                     }                                     if (hit != null &&                                         !assigned.containsKey(hit) &&-                                        question.correctRightForLeft[hit] == ri+                                        question.correctRightForLeft.getOrNull(hit) == ri                                     ) {                                         assigned[hit] = ri                                         if (assigned.size == question.left.size) onSolved()