-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
🛠️ Refactor suggestion
Potential NPE when column name absent → use getColumnIndexOrThrow
cursor.getColumnIndex(columnNameAndroidId) returns -1 when the column is missing; the subsequent getString call will crash. Use getColumnIndexOrThrow to fail fast with a clear exception, or handle -1 gracefully.
- val columnAndroidId = cursor.getColumnIndex(columnNameAndroidId)
+ val columnAndroidId = cursor.getColumnIndexOrThrow(columnNameAndroidId)Replicate for all dynamic columns.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
val columnNameAndroidId = bundle.getString("column_name_android_id")
Log.i(TAG, "columnNameAndroidId: ${columnNameAndroidId}")
val columnAndroidId = cursor.getColumnIndexOrThrow(columnNameAndroidId)
val androidId = cursor.getString(columnAndroidId)
Log.i(
🤖 Prompt for AI Agents
In
utils/src/main/java/ai/elimu/analytics/utils/converter/CursorToWordLearningEventGsonConverter.kt
around lines 31 to 35, replace all calls to cursor.getColumnIndex with
cursor.getColumnIndexOrThrow to avoid returning -1 when a column is missing,
which causes a crash on subsequent getString calls. This change will cause the
code to fail fast with a clear exception if a column is absent. Apply this fix
consistently for all dynamic column name lookups in the method.
Originally posted by @coderabbitai[bot] in #334 (comment)