{"record":{"id":"46ecfb54eae2d5fb","repo":"Tencent/QMUI_Android","slug":"use-appendwholelistcustomindex-for-whole-list","errorCode":null,"errorMessage":"use appendWholeListCustomIndex for whole list","messagePattern":"use appendWholeListCustomIndex for whole list","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/section/QMUISectionDiffCallback.java","lineNumber":294,"sourceCode":"\n        private IndexGenerationInfo(ArrayList<Integer> sectionIndex, ArrayList<Integer> itemIndex) {\n            sectionIndexArray = sectionIndex;\n            itemIndexArray = itemIndex;\n        }\n\n        public final void appendCustomIndex(int sectionIndex, int itemIndex) {\n\n            int offset = QMUISection.ITEM_INDEX_CUSTOM_OFFSET + itemIndex;\n            if(!QMUISection.isCustomItemIndex(offset)){\n                throw new IllegalArgumentException(\n                        \"Index conflicts with index used internally, please use negative number for custom item\");\n            }\n            appendIndex(sectionIndex, offset);\n        }\n\n        private void appendIndex(int sectionIndex, int itemIndex) {\n            if (sectionIndex < 0) {\n                throw new IllegalArgumentException(\"use appendWholeListCustomIndex for whole list\");\n            }\n            sectionIndexArray.add(sectionIndex);\n            itemIndexArray.add(itemIndex);\n        }\n\n        public final void appendWholeListCustomIndex(int itemIndex) {\n            int offset = QMUISection.ITEM_INDEX_CUSTOM_OFFSET + itemIndex;\n            if(!QMUISection.isCustomItemIndex(offset)){\n                throw new IllegalArgumentException(\n                        \"Index conflicts with index used internally, please use negative number for custom item\");\n            }\n            appendWholeListIndex(offset);\n        }\n\n        private void appendWholeListIndex(int itemIndex) {\n            sectionIndexArray.add(QMUISection.SECTION_INDEX_UNKNOWN);\n            itemIndexArray.add(itemIndex);\n        }","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/section/QMUISectionDiffCallback.java#L276-L312","documentation":"QMUISectionDiffCallback.appendIndex (private) throws an IllegalArgumentException when sectionIndex is negative. A negative section index means the caller wanted a whole-list custom entry, which must go through the dedicated appendWholeListCustomIndex method rather than appendIndex (reachable via appendCustomIndex).","triggerScenarios":"Calling appendCustomIndex(-1, itemIndex) (or any negative sectionIndex) instead of appendWholeListCustomIndex(itemIndex); passing a sentinel negative value to denote 'no section' into appendCustomIndex.","commonSituations":"Using -1 as a conventional 'whole list' marker learned from other APIs; writing a custom wrapper that forwards negative section indices to appendCustomIndex.","solutions":["Replace callback.appendCustomIndex(negativeIndex, itemIndex) with callback.appendWholeListCustomIndex(itemIndex).","Validate sectionIndex >= 0 before calling appendCustomIndex.","For section-scoped custom items always pass a valid, non-negative section index."],"exampleFix":"// before\ncallback.appendCustomIndex(-1, customIndex); // wrong API\n// after\ncallback.appendWholeListCustomIndex(customIndex);","handlingStrategy":"validation","validationCode":"if (sectionIndex >= 0) {\n    callback.appendCustomIndex(sectionIndex, itemIndex);\n} else {\n    callback.appendWholeListCustomIndex(itemIndex);\n}","typeGuard":null,"tryCatchPattern":"try {\n    callback.appendCustomIndex(sectionIndex, itemIndex);\n} catch (IllegalArgumentException e) {\n    callback.appendWholeListCustomIndex(itemIndex);\n}","preventionTips":["Use appendWholeListCustomIndex for entries not tied to a section; never pass -1 as sectionIndex.","Assert sectionIndex >= 0 before appendCustomIndex.","Don't reuse sentinel negative values from other APIs as section indices here."],"tags":["android","qmui","diffutil","wrong-api-usage"],"backgroundTag":"invalid-argument-value","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}