{"record":{"id":"89c845e7ccf3beb2","repo":"krahets/hello-algo","slug":"error-89c845","errorCode":null,"errorMessage":"インデックスが範囲外です","messagePattern":"インデックスが範囲外です","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/codes/go/chapter_array_and_linkedlist/my_list.go","lineNumber":39,"sourceCode":"\t\textendRatio: 2,               // リスト拡張時の増加倍率\n\t}\n}\n\n/* リストの長さを取得（現在の要素数） */\nfunc (l *myList) size() int {\n\treturn l.arrSize\n}\n\n/* リスト容量を取得する */\nfunc (l *myList) capacity() int {\n\treturn l.arrCapacity\n}\n\n/* 要素にアクセス */\nfunc (l *myList) get(index int) int {\n\t// インデックスが範囲外なら例外を送出する。以下同様\n\tif index < 0 || index >= l.arrSize {\n\t\tpanic(\"インデックスが範囲外です\")\n\t}\n\treturn l.arr[index]\n}\n\n/* 要素を更新 */\nfunc (l *myList) set(num, index int) {\n\tif index < 0 || index >= l.arrSize {\n\t\tpanic(\"インデックスが範囲外です\")\n\t}\n\tl.arr[index] = num\n}\n\n/* 末尾に要素を追加 */\nfunc (l *myList) add(num int) {\n\t// 要素数が容量を超えると、拡張機構が発動する\n\tif l.arrSize == l.arrCapacity {\n\t\tl.extendCapacity()\n\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/go/chapter_array_and_linkedlist/my_list.go#L21-L57","documentation":"`get(index)` in the Japanese `myList` panics with \"インデックスが範囲外です\" (index out of range) when the position is outside `[0, arrSize-1]`. It is the read-side bounds guard of this tutorial dynamic array.","triggerScenarios":"Reading with `index < 0` or `index >= arrSize`; reading an empty list; using capacity instead of size for bounds math.","commonSituations":"Off-by-one loop bounds, `capacity()`/`size()` confusion, or a stale index kept across a mutating operation.","solutions":["Gate reads with `0 <= index < l.size()`.","Loop with `i < l.size()`, not `i <= l.size()`.","Use `size()` for valid-index arithmetic.","Recover at boundaries that accept caller indices."],"exampleFix":"// before\nv := l.get(i) // インデックスが範囲外です\n\n// after\nif i >= 0 && i < l.size() {\n    v = l.get(i)\n}","handlingStrategy":"validation","validationCode":"if i < 0 || i >= l.size() {\n    return 0, errors.New(\"index out of range\")\n}\nreturn l.get(i), nil","typeGuard":"func (l *myList) validIndex(i int) bool {\n    return i >= 0 && i < l.arrSize\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        // return a safe default instead of crashing on a bad read\n    }\n}()\nv = l.get(i)","preventionTips":["Use size(), not capacity(), for valid-index math.","Iterate with `i < l.size()`.","Recompute indices after any mutation."],"tags":["go","array-list","index-out-of-bounds","panic","teaching-example"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}