Tencent/QMUI_Android · error · IllegalArgumentException

use appendWholeListCustomIndex for whole list

Error message

use appendWholeListCustomIndex for whole list

What it means

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).

Source

Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/section/QMUISectionDiffCallback.java:294

        private IndexGenerationInfo(ArrayList<Integer> sectionIndex, ArrayList<Integer> itemIndex) {
            sectionIndexArray = sectionIndex;
            itemIndexArray = itemIndex;
        }

        public final void appendCustomIndex(int sectionIndex, int itemIndex) {

            int offset = QMUISection.ITEM_INDEX_CUSTOM_OFFSET + itemIndex;
            if(!QMUISection.isCustomItemIndex(offset)){
                throw new IllegalArgumentException(
                        "Index conflicts with index used internally, please use negative number for custom item");
            }
            appendIndex(sectionIndex, offset);
        }

        private void appendIndex(int sectionIndex, int itemIndex) {
            if (sectionIndex < 0) {
                throw new IllegalArgumentException("use appendWholeListCustomIndex for whole list");
            }
            sectionIndexArray.add(sectionIndex);
            itemIndexArray.add(itemIndex);
        }

        public final void appendWholeListCustomIndex(int itemIndex) {
            int offset = QMUISection.ITEM_INDEX_CUSTOM_OFFSET + itemIndex;
            if(!QMUISection.isCustomItemIndex(offset)){
                throw new IllegalArgumentException(
                        "Index conflicts with index used internally, please use negative number for custom item");
            }
            appendWholeListIndex(offset);
        }

        private void appendWholeListIndex(int itemIndex) {
            sectionIndexArray.add(QMUISection.SECTION_INDEX_UNKNOWN);
            itemIndexArray.add(itemIndex);
        }

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Replace callback.appendCustomIndex(negativeIndex, itemIndex) with callback.appendWholeListCustomIndex(itemIndex).
  2. Validate sectionIndex >= 0 before calling appendCustomIndex.
  3. For section-scoped custom items always pass a valid, non-negative section index.

Example fix

// before
callback.appendCustomIndex(-1, customIndex); // wrong API
// after
callback.appendWholeListCustomIndex(customIndex);
Defensive patterns

Strategy: validation

Validate before calling

if (sectionIndex >= 0) {
    callback.appendCustomIndex(sectionIndex, itemIndex);
} else {
    callback.appendWholeListCustomIndex(itemIndex);
}

Try / catch

try {
    callback.appendCustomIndex(sectionIndex, itemIndex);
} catch (IllegalArgumentException e) {
    callback.appendWholeListCustomIndex(itemIndex);
}

Prevention

When it happens

Trigger: Calling appendCustomIndex(-1, itemIndex) (or any negative sectionIndex) instead of appendWholeListCustomIndex(itemIndex); passing a sentinel negative value to denote 'no section' into appendCustomIndex.

Common situations: Using -1 as a conventional 'whole list' marker learned from other APIs; writing a custom wrapper that forwards negative section indices to appendCustomIndex.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/46ecfb54eae2d5fb. Report an issue: GitHub.