java-native-access/jna · error · UnsupportedOperationException
This pointer is opaque:
Error message
This pointer is opaque:
What it means
JNA's Pointer.Opaque throws UnsupportedOperationException with the message "This pointer is opaque: " + this for every memory operation. This entry is the short[] write overload: opaque memory must not be mutated.
Solutions
- Do not write via the opaque pointer; use it only to identify the native object.
- Allocate a Memory buffer, write the short[] there, and pass it to a native function.
- Check the pointer for opacity before writing.
- Expose a native setter (e.g. void set(Handle, short*, int)) and call it with the handle.
Example fix
// before
Pointer opaque = lib.getHandle();
opaque.write(0, new short[]{1, 2}, 0, 2); // throws
// after
Memory mem = new Memory(4);
mem.write(0, new short[]{1, 2}, 0, 2);
lib.setHandleShorts(opaque, mem, 2); Defensive patterns
Strategy: try-catch
Validate before calling
if (p == null || p.toString().startsWith("opaque@")) {
throw new IllegalArgumentException("cannot write short[] to opaque pointer");
} Type guard
public static boolean supportsWrite(Pointer p) {
return p != null && !p.toString().startsWith("opaque@");
} Try / catch
try {
p.write(bOff, buf, 0, len);
} catch (UnsupportedOperationException e) {
if (String.valueOf(e.getMessage()).contains("opaque")) {
Memory mem = new Memory((long) len * 2);
mem.write(0, buf, 0, len);
nativeSetShorts(handle, mem, len);
return;
}
throw e;
} Prevention
- Allocate Memory for buffer writes; never mutate handles.
- Guard all write helpers with an opacity check.
- Treat native-returned handles as immutable identifiers.
- Write integration tests that call every native accessor to surface opaque returns early.
When it happens
Trigger: Calling Pointer.write(long bOff, short[] buf, int index, int length) on a Pointer.Opaque instance.
Common situations: Filling short arrays (e.g. audio samples, 16-bit data) through a handle obtained from Pointer.createOpaque or an opaque native return value.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Bounds exceeds available space : size=
- Byte boundary must be a power of two
- Insufficient memory to align to the requested boundary
- Invalid offset
- Maximum argument count is
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/73ad5539649bea80.
Report an issue: GitHub.
Appendix: source
Thrown at src/com/sun/jna/Pointer.java:1260
@Override
public void read(long bOff, Pointer[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, byte[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, char[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, short[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, int[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, long[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, float[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, double[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@Override
public void write(long bOff, Pointer[] buf, int index, int length) {
throw new UnsupportedOperationException(MSG);
}
@OverrideView on GitHub (pinned to d036ad9781)