{"record":{"id":"d25ed40c5fa320bc","repo":"Tencent/QMUI_Android","slug":"index-conflicts-with-index-used-internally-please","errorCode":null,"errorMessage":"Index conflicts with index used internally, please use negative number for custom item","messagePattern":"Index conflicts with index used internally, please use negative number for custom item","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/section/QMUISectionDiffCallback.java","lineNumber":286,"sourceCode":"\n        return (oldItem == null && newItem == null) ||\n                (oldItem != null && newItem != null && oldItem.isSameContent(newItem));\n    }\n\n    public static class IndexGenerationInfo {\n        private ArrayList<Integer> sectionIndexArray;\n        private ArrayList<Integer> itemIndexArray;\n\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\");","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/section/QMUISectionDiffCallback.java#L268-L304","documentation":"QMUISectionDiffCallback.appendCustomIndex throws an IllegalArgumentException when the computed offset (ITEM_INDEX_CUSTOM_OFFSET + itemIndex) is not recognized as a custom item index. This happens when itemIndex is too large (or mis-ranged), colliding with indexes the section framework uses internally for real items.","triggerScenarios":"Calling callback.appendCustomIndex(sectionIndex, itemIndex) with a non-negative or very large itemIndex such that offset no longer satisfies QMUISection.isCustomItemIndex(offset) — i.e. the custom index bleeds into the internal positive-index space.","commonSituations":"Passing an item position from the real list instead of a small custom identifier; computing a custom index by adding your own offset on top of the library's; custom index space exhausted because itemIndex exceeds the custom range.","solutions":["Use a small custom item identifier (0-based within your custom set) so ITEM_INDEX_CUSTOM_OFFSET + itemIndex lands in the custom negative range.","Remove any extra offset you add yourself; the library already applies ITEM_INDEX_CUSTOM_OFFSET.","If you need whole-list custom entries, call appendWholeListCustomIndex instead."],"exampleFix":"// before\ncallback.appendCustomIndex(sectionIndex, itemList.size()); // collides with internal indexes\n// after\ncallback.appendCustomIndex(sectionIndex, 0); // small custom identifier for your custom row","handlingStrategy":"validation","validationCode":"if (itemIndex >= 0 && QMUISection.isCustomItemIndex(QMUISection.ITEM_INDEX_CUSTOM_OFFSET + itemIndex)) {\n    callback.appendCustomIndex(sectionIndex, itemIndex);\n}","typeGuard":null,"tryCatchPattern":"try {\n    callback.appendCustomIndex(sectionIndex, itemIndex);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"custom itemIndex out of custom range; use a small custom id\", e);\n}","preventionTips":["Use small, zero-based custom identifiers, not real list positions or sizes.","Never add your own offset — the library already applies ITEM_INDEX_CUSTOM_OFFSET.","Model custom items with a small enum or counter instead of positions."],"tags":["android","qmui","diffutil","index-out-of-range"],"backgroundTag":"value-out-of-range","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"}