{"record":{"id":"301e4f7a71ae54a3","repo":"libgdx/libgdx","slug":"indexoutofboundsexception","errorCode":null,"errorMessage":"IndexOutOfBoundsException","messagePattern":"IndexOutOfBoundsException","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java","lineNumber":58,"sourceCode":"\t\tthis(capacity, new double[capacity], 0);\n\t}\n\n\tDoubleArrayBuffer (int capacity, double[] backingArray, int offset) {\n\t\tsuper(capacity);\n\t\tthis.backingArray = backingArray;\n\t\tthis.offset = offset;\n\t}\n\n\tpublic final double get () {\n\t\tif (position == limit) {\n\t\t\tthrow new BufferUnderflowException();\n\t\t}\n\t\treturn backingArray[offset + position++];\n\t}\n\n\tpublic final double get (int index) {\n\t\tif (index < 0 || index >= limit) {\n\t\t\tthrow new IndexOutOfBoundsException();\n\t\t}\n\t\treturn backingArray[offset + index];\n\t}\n\n\tpublic final DoubleBuffer get (double[] dest, int off, int len) {\n\t\tint length = dest.length;\n\t\tif (off < 0 || len < 0 || (long)off + (long)len > length) {\n\t\t\tthrow new IndexOutOfBoundsException();\n\t\t}\n\t\tif (len > remaining()) {\n\t\t\tthrow new BufferUnderflowException();\n\t\t}\n\t\tSystem.arraycopy(backingArray, offset + position, dest, off, len);\n\t\tposition += len;\n\t\treturn this;\n\t}\n\n\tpublic final boolean isDirect () {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java#L40-L76","documentation":"DoubleArrayBuffer.get(int index) throws IndexOutOfBoundsException when index < 0 or index >= limit. Absolute gets are validated against the buffer's limit (not capacity), per the java.nio contract, so even in-bounds-capacity indexes beyond the limit are rejected. This protects the backing array access backingArray[offset + index] from going out of range.","triggerScenarios":"Calling get(i) with i >= limit — e.g. index computed from capacity after a flip()/slice() reduced the limit, or negative index from a subtraction that underflowed. The check fires before any array access.","commonSituations":"Iterating with for (i=0; i<buf.capacity(); i++) buf.get(i) after limit was set smaller; using an index relative to a parent buffer on a slice; arithmetic producing -1 used as an index.","solutions":["Iterate against limit: for (int i = 0; i < buf.limit(); i++) ...","Clamp/validate index before use: if (index < 0 || index >= buf.limit()) throw/log.","After slicing or flipping, recompute indexes relative to the new buffer's own coordinate space."],"exampleFix":"// before\nfor (int i = 0; i < buf.capacity(); i++) sum += buf.get(i); // may throw\n\n// after\nfor (int i = 0; i < buf.limit(); i++) sum += buf.get(i);","handlingStrategy":"validation","validationCode":"// validate against limit, not capacity\nif (index >= 0 && index < buf.limit()) {\n  double v = buf.get(index);\n} else {\n  throw new IllegalArgumentException(\"index \" + index + \" outside [0,\" + buf.limit() + \")\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Iterate to limit(), not capacity().","Recompute indices after slice()/flip(); child buffers have their own coordinate space.","Guard against negative indices from indexOf-style calls returning -1."],"tags":["gwt","libgdx","nio","doublebuffer","index-out-of-bounds"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}