{"record":{"id":"4839044d00aa558f","repo":"libgdx/libgdx","slug":"unsupportedoperationexception-483904","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/FloatToByteBufferAdapter.java","lineNumber":162,"sourceCode":"\n\t@Override\n\tpublic boolean isDirect () {\n\t\treturn byteBuffer.isDirect();\n\t}\n\n\t@Override\n\tpublic boolean isReadOnly () {\n\t\treturn byteBuffer.isReadOnly();\n\t}\n\n\t@Override\n\tpublic ByteOrder order () {\n\t\treturn byteBuffer.order();\n\t}\n\n\t@Override\n\tprotected float[] 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 FloatBuffer put (float c) {\n\t\tif (position == limit) {\n\t\t\tthrow new BufferOverflowException();\n\t\t}\n\t\tbyteBuffer.putFloat(position++ << 2, c);","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java#L144-L180","documentation":"Thrown by FloatToByteBufferAdapter.protectedArray(), which backs the public array() accessor. Adapter buffers have no float[] backing array — their storage lives in a ByteBuffer — so any attempt to obtain the array throws UnsupportedOperationException, consistent with hasArray() returning false. This is by design, not corruption.","triggerScenarios":"Calling array() (or code that calls it, e.g. some serialization or IO helpers) on a FloatBuffer created through FloatToByteBufferAdapter rather than FloatBuffer.allocate/wrap.","commonSituations":"Utility code that assumes array() works because it was tested with heap FloatBuffers; switching a GWT renderer from array-backed buffers to ByteBuffer-adapter buffers for direct-memory semantics; third-party libraries (e.g. JSON or mesh serializers) calling array() internally.","solutions":["Check hasArray() before calling array() and take a copy path when false: if (buf.hasArray()) use buf.array() else copy via get(float[]).","Replace array() access with a bulk read: float[] out = new float[buf.remaining()]; buf.get(out);","Construct the buffer with FloatBuffer.allocate() or FloatBuffer.wrap(float[]) when array access is required.","Catch UnsupportedOperationException and degrade gracefully if you cannot change the call site."],"exampleFix":"// before\nfloat[] data = buf.array(); // UnsupportedOperationException on adapter buffers\n\n// after\nfloat[] data = new float[buf.remaining()];\nbuf.get(data);","handlingStrategy":"type-guard","validationCode":"// before buf.array()\nif (!buf.hasArray()) {\n    // adapter buffer: no float[] backing\n    float[] copy = new float[buf.remaining()];\n    buf.get(copy);\n    // use copy\n} else {\n    float[] arr = buf.array();\n}","typeGuard":"static boolean hasFloatArray(FloatBuffer b) { return b != null && b.hasArray(); }","tryCatchPattern":"try { float[] a = buf.array(); } catch (UnsupportedOperationException e) { /* no backing array: copy via get(float[]) */ }","preventionTips":["Gate every array() call behind hasArray().","Prefer bulk get(float[]) in generic helpers so they work with any buffer implementation.","When array access is a hard requirement, build buffers with allocate()/wrap(), not ByteBuffer adapters."],"tags":["libgdx","gwt","java-nio","unsupported-operation","backing-array"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}