{"record":{"id":"5f3568def3e408d4","repo":"krahets/hello-algo","slug":"error-5f3568","errorCode":null,"errorMessage":"индекс выходит за границы","messagePattern":"индекс выходит за границы","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"ru/codes/java/chapter_array_and_linkedlist/my_list.java","lineNumber":37,"sourceCode":"    public MyList() {\n        arr = new int[capacity];\n    }\n\n    /* Получить длину списка (текущее число элементов) */\n    public int size() {\n        return size;\n    }\n\n    /* Получить вместимость списка */\n    public int capacity() {\n        return capacity;\n    }\n\n    /* Доступ к элементу */\n    public int get(int index) {\n        // Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"индекс выходит за границы\");\n        return arr[index];\n    }\n\n    /* Обновление элемента */\n    public void set(int index, int num) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"индекс выходит за границы\");\n        arr[index] = num;\n    }\n\n    /* Добавление элемента в конец */\n    public void add(int num) {\n        // При превышении вместимости по числу элементов запускается расширение\n        if (size == capacity())\n            extendCapacity();\n        arr[size] = num;\n        // Обновить число элементов\n        size++;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/java/chapter_array_and_linkedlist/my_list.java#L19-L55","documentation":"Russian-translation twin of error 200: thrown by get() in MyList (ru/codes/java). Same guard — index must be 0 <= index < size. The message 'индекс выходит за границы' means 'index goes out of bounds'. The class is the same pedagogical dynamic-array reimplementation; only the localized string differs from the ja build.","triggerScenarios":"myList.get(-1); myList.get(size); myList.get(0) on an empty list; using capacity() instead of size() as a loop ceiling; index sourced from a collection of different length.","commonSituations":"Off-by-one read loop (`<=` instead of `<`); capacity/size confusion; stale index after concurrent remove; 1-based indexing assumptions.","solutions":["Bounds-check before access: `if (index >= 0 && index < list.size()) list.get(index);`","Use `< list.size()` as the loop bound, reading size() live each iteration.","Distinguish size() (live count) from capacity() (backing length).","Switch to java.util.ArrayList for non-pedagogical use."],"exampleFix":"// before\nfor (int i = 0; i <= list.capacity(); i++) list.get(i); // IndexOutOfBoundsException\n// after\nfor (int i = 0; i < list.size(); i++) list.get(i);","handlingStrategy":"validation","validationCode":"if (index < 0 || index >= list.size()) {\n    throw new IllegalArgumentException(\"bad index: \" + index);\n}\nint v = list.get(index);","typeGuard":null,"tryCatchPattern":"try {\n    int v = list.get(index);\n} catch (IndexOutOfBoundsException e) {\n    // index outside [0, size); recover\n}","preventionTips":["Loop with `i < list.size()`, re-reading size() under mutation.","Never use capacity() in place of size().","Centralize index checks in a helper."],"tags":["java","array","bounds-check","data-structures","i18n-ru"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}