{"record":{"id":"2585f9f1388326a1","repo":"krahets/hello-algo","slug":"error-2585f9","errorCode":null,"errorMessage":"индекс выходит за границы","messagePattern":"индекс выходит за границы","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/javascript/chapter_array_and_linkedlist/my_list.js","lineNumber":32,"sourceCode":"    /* Конструктор */\n    constructor() {\n        this.#arr = new Array(this.#capacity);\n    }\n\n    /* Получить длину списка (текущее число элементов) */\n    size() {\n        return this.#size;\n    }\n\n    /* Получить вместимость списка */\n    capacity() {\n        return this.#capacity;\n    }\n\n    /* Доступ к элементу */\n    get(index) {\n        // Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n        if (index < 0 || index >= this.#size) throw new Error('индекс выходит за границы');\n        return this.#arr[index];\n    }\n\n    /* Обновление элемента */\n    set(index, num) {\n        if (index < 0 || index >= this.#size) throw new Error('индекс выходит за границы');\n        this.#arr[index] = num;\n    }\n\n    /* Добавление элемента в конец */\n    add(num) {\n        // Если длина равна вместимости, требуется расширение\n        if (this.#size === this.#capacity) {\n            this.extendCapacity();\n        }\n        // Добавить новый элемент в конец списка\n        this.#arr[this.#size] = num;\n        this.#size++;","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/javascript/chapter_array_and_linkedlist/my_list.js#L14-L50","documentation":"Thrown by get(index) on the custom MyList when `index < 0 || index >= this.#size`. Plain Error with a Russian message ('index out of bounds'). It guards read access against the logical size (#size), not the backing array capacity (#capacity).","triggerScenarios":"Calling get(-1); calling get(size) (one past the last valid index); calling get on a freshly constructed list with no added elements; using an index from a deserialized list whose size was not restored.","commonSituations":"Off-by-one loops `for (i=0; i<=size; i++)`; confusing size with capacity; ignoring the return of remove/shrink and reusing a stale index; user-supplied index not validated.","solutions":["Bounds-check `index >= 0 && index < list.size()` before get.","Use `for (i=0; i<list.size(); i++)` (strict less-than).","Validate external/deserialized indices before access."],"exampleFix":"// before\nconst v = list.get(idx);\n\n// after\nconst v = (idx >= 0 && idx < list.size()) ? list.get(idx) : undefined;","handlingStrategy":"validation","validationCode":"// Bounds-check against logical size before get.\nif (index >= 0 && index < list.size()) {\n  const v = list.get(index);\n}","typeGuard":"function isValidListIndex(list, index) {\n  return Number.isInteger(index) && index >= 0 && index < list.size();\n}","tryCatchPattern":"try {\n  const v = list.get(index);\n} catch (e) {\n  if (e instanceof Error && e.message === 'индекс выходит за границы') {\n    // out-of-range access\n  } else throw e;\n}","preventionTips":["Loop with strict `i < list.size()`, never `i <= size`.","Validate user-supplied or deserialized indices before access.","Remember bounds are against size, not capacity.","Recompute indices after remove/insert."],"tags":["list","index-out-of-bounds","range-check","javascript"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}