{"record":{"id":"be923eee7cadffc2","repo":"libgdx/libgdx","slug":"unsupportedoperationexception-be923e","errorCode":null,"errorMessage":"UnsupportedOperationException","messagePattern":"UnsupportedOperationException","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java","lineNumber":116,"sourceCode":"\n\t@Override\n\tpublic boolean isDirect () {\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic boolean isReadOnly () {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic ByteOrder order () {\n\t\treturn byteBuffer.order();\n\t}\n\n\t@Override\n\tprotected short[] protectedArray () {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tprotected int protectedArrayOffset () {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tprotected boolean protectedHasArray () {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic ShortBuffer put (short c) {\n// if (position == limit) {\n// throw new BufferOverflowException();\n// }\n\t\tshortArray.set(position++, c);","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java#L98-L134","documentation":"DirectReadWriteShortBufferAdapter — the ShortBuffer view of a GWT emulated direct ByteBuffer (asShortBuffer()) — throws UnsupportedOperationException from protectedArray() because a direct view has no short[] backing array. The emulated ShortBuffer.array() delegates to this method, so any array() call on the view throws. protectedHasArray() returns false, so hasArray() is the correct pre-check.","triggerScenarios":"Calling shortBuffer.array() on a ShortBuffer from ByteBuffer.asShortBuffer() in a GWT build; typical in vertex-data builders that memcpy from the raw array, or audio code that assumed a heap buffer.","commonSituations":"Mesh construction via FloatBuffer/ShortBuffer views that worked on desktop JVM direct buffers with array() hacks; libraries calling array() without checking hasArray().","solutions":["Check sb.hasArray() first; for direct views, bulk-copy with sb.get(short[]) or use relative/absolute puts.","Build data in a short[] then ShortBuffer.wrap(arr) or use put(short[]) instead of exposing the internal array.","Use libGDX's ShortArray or number-utils array helpers on GWT instead of nio array access."],"exampleFix":"// before\nshort[] verts = sb.array(); // UnsupportedOperationException\n\n// after\nshort[] verts = new short[sb.remaining()];\nsb.get(verts);","handlingStrategy":"type-guard","validationCode":"if (sb.hasArray()) {\n  short[] arr = sb.array();\n} else {\n  short[] arr = new short[sb.remaining()];\n  sb.get(arr);\n}","typeGuard":"boolean isHeapBacked(ShortBuffer sb) {\n  return sb != null && sb.hasArray();\n}","tryCatchPattern":"try {\n  short[] a = sb.array();\n} catch (UnsupportedOperationException e) {\n  short[] a = new short[sb.remaining()];\n  sb.get(a);\n}","preventionTips":["Guard every array() call with hasArray() in cross-platform code.","Use put(short[]) to fill buffers instead of exposing internals.","Test mesh/vertex builders under the GWT backend where views are direct."],"tags":["gwt","libgdx","nio","shortbuffer","direct-buffer"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}