libgdx/libgdx · error · UnsupportedOperationException
UnsupportedOperationException
Error message
UnsupportedOperationException
What it means
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.
Source
Thrown at backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java:162
@Override
public boolean isDirect () {
return byteBuffer.isDirect();
}
@Override
public boolean isReadOnly () {
return byteBuffer.isReadOnly();
}
@Override
public ByteOrder order () {
return byteBuffer.order();
}
@Override
protected float[] protectedArray () {
throw new UnsupportedOperationException();
}
@Override
protected int protectedArrayOffset () {
throw new UnsupportedOperationException();
}
@Override
protected boolean protectedHasArray () {
return false;
}
@Override
public FloatBuffer put (float c) {
if (position == limit) {
throw new BufferOverflowException();
}
byteBuffer.putFloat(position++ << 2, c);View on GitHub (pinned to 97f4086187)
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.
Example fix
// before float[] data = buf.array(); // UnsupportedOperationException on adapter buffers // after float[] data = new float[buf.remaining()]; buf.get(data);
Defensive patterns
Strategy: type-guard
Validate before calling
// before buf.array()
if (!buf.hasArray()) {
// adapter buffer: no float[] backing
float[] copy = new float[buf.remaining()];
buf.get(copy);
// use copy
} else {
float[] arr = buf.array();
} Type guard
static boolean hasFloatArray(FloatBuffer b) { return b != null && b.hasArray(); } Try / catch
try { float[] a = buf.array(); } catch (UnsupportedOperationException e) { /* no backing array: copy via get(float[]) */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- libGDX requires Android API Level " + MINIMUM_SDK + " or lat
- FileType '
- file() not supported in GWT backend
- Cannot map files in GWT backend
- Cannot write to files in GWT backend
AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14).
Data as JSON: /api/errors/4839044d00aa558f.
Report an issue: GitHub.