{"record":{"id":"3e9e0a3a14c08b52","repo":"apache/dubbo","slug":"index-index-size-msize","errorCode":null,"errorMessage":"Index: ${index}, Size: ${mSize}","messagePattern":"Index: (.+?), Size: (.+?)","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/Stack.java","lineNumber":79,"sourceCode":"     *\n     * @return the last element.\n     */\n    public E peek() {\n        if (mSize == 0) {\n            throw new EmptyStackException();\n        }\n        return mElements.get(mSize - 1);\n    }\n\n    /**\n     * get.\n     *\n     * @param index index.\n     * @return element.\n     */\n    public E get(int index) {\n        if (index >= mSize || index + mSize < 0) {\n            throw new IndexOutOfBoundsException(\"Index: \" + index + \", Size: \" + mSize);\n        }\n\n        return index < 0 ? mElements.get(index + mSize) : mElements.get(index);\n    }\n\n    /**\n     * set.\n     *\n     * @param index index.\n     * @param value element.\n     * @return old element.\n     */\n    public E set(int index, E value) {\n        if (index >= mSize || index + mSize < 0) {\n            throw new IndexOutOfBoundsException(\"Index: \" + index + \", Size: \" + mSize);\n        }\n\n        return mElements.set(index < 0 ? index + mSize : index, value);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/Stack.java#L61-L97","documentation":"Thrown by Stack.get(int index) when index is out of bounds. The guard checks two conditions: index >= mSize (too large) or index + mSize < 0 (excessively negative, since negative indices wrap from the end). The message reports the offending index and current size. Negative indices are supported as offsets from the top.","triggerScenarios":"Calling get(size) or get(size + n) (one-past-end or beyond); calling get(-n) where n > mSize (negative index more negative than -size); calling get on an empty stack (any non-negative index triggers since 0 >= 0).","commonSituations":"Off-by-one loop: for (int i = 0; i <= stack.size(); i++) instead of <; using get(0) on an empty stack; index computed from external input without clamping.","solutions":["Check bounds before access: if (index >= 0 && index < stack.size()) { ... }.","Fix off-by-one in loops: use < stack.size() not <= stack.size().","For negative indices, ensure the absolute value does not exceed stack.size()."],"exampleFix":"// before\nfor (int i = 0; i <= stack.size(); i++) {\n    E e = stack.get(i);\n}\n\n// after\nfor (int i = 0; i < stack.size(); i++) {\n    E e = stack.get(i);\n}","handlingStrategy":"validation","validationCode":"if (index >= 0 && index < stack.size()) {\n    E val = stack.get(index);\n} else {\n    // handle out-of-bounds\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use < stack.size() (not <=) in loops.","Remember negative indices wrap from the top: get(-1) is the last element."],"tags":["data-structure","index-out-of-bounds","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}