java-native-access/jna · error · IllegalArgumentException
Wrong array size !
Error message
Wrong array size !
What it means
ARRAYDESC's full constructor takes an rgbounds array that must have exactly one SAFEARRAYBOUND per declared dimension slot (the embedded fixed-size array). If the supplied array length does not match the fixed-size rgbounds field length, IllegalArgumentException 'Wrong array size !' is thrown.
Solutions
- Pass exactly as many SAFEARRAYBOUND entries as the ARRAYDESC.rgbounds field expects (allocate the fixed-size array via new SAFEARRAYBOUND[1])
- Set cDims consistently with the bounds array
- Build ARRAYDESC by assigning fields directly if you need a different number of bounds
- Validate rgbounds.length before construction
Example fix
// before ARRAYDESC d = new ARRAYDESC(tdesc, cDims, new SAFEARRAYBOUND[0]); // after SAFEARRAYBOUND[] bounds = (SAFEARRAYBOUND[]) new SAFEARRAYBOUND().toArray(1); bounds[0].lLbound = 0; bounds[0].cElements = 10; ARRAYDESC d = new ARRAYDESC(tdesc, (short) 1, bounds);
Defensive patterns
Strategy: validation
Validate before calling
if (rgbounds == null || rgbounds.length != 1) throw new IllegalArgumentException("ARRAYDESC expects exactly " + 1 + " bound(s)"); Try / catch
try {
new ARRAYDESC(tdescElem, cDims, rgbounds);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Wrong array size")) { /* reallocate bounds array */ }
else throw e;
} Prevention
- Allocate bounds via new SAFEARRAYBOUND().toArray(1) to match the fixed-size field
- Keep cDims and rgbounds length consistent
- Validate bounds arrays before constructing ARRAYDESC
- Read the Javadoc: the fixed rgbounds field dictates the required length
When it happens
Trigger: Constructing new OaIdl.ARRAYDESC(tdescElem, cDims, rgbounds) where rgbounds.length does not equal the structure's fixed rgbounds field length (1) — e.g. passing an empty array or more than one bound for the declared dimensions.
Common situations: Building multi-dimensional array type descriptors for IDispatch::GetTypeInfo; passing a dynamically-sized bounds list without matching the fixed field; forgetting to allocate SAFEARRAYBOUND entries.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Supplied Array has no dimensions.
- advise: Interface must define a value for either iid via…
- advise: Interface must define a value for either iid via…
- Bad volume GUID path format:
- Byte boundary must be positive
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/bb2793474d6ffdc0.
Report an issue: GitHub.
Appendix: source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java:1839
public ARRAYDESC(Pointer pointer) {
super(pointer);
this.read();
}
/**
* @param tdescElem
* C type : TYPEDESC<br>
* @param cDims dimensions
* @param rgbounds
* [size_is]<br>
* C type : SAFEARRAYBOUND[1]
*/
public ARRAYDESC(TYPEDESC tdescElem, short cDims, SAFEARRAYBOUND rgbounds[]) {
this.tdescElem = tdescElem;
this.cDims = cDims;
if (rgbounds.length != this.rgbounds.length)
throw new IllegalArgumentException("Wrong array size !");
this.rgbounds = rgbounds;
}
public static class ByReference extends ARRAYDESC implements
Structure.ByReference {
};
}
@FieldOrder({"pparamdescex", "wParamFlags"})
public static class PARAMDESC extends Structure {
public static class ByReference extends PARAMDESC implements
Structure.ByReference {
}
// replaced PARAMDESCEX.ByReference with Pointer
// because of JNA 4 has a problem with ByReference
public Pointer pparamdescex;View on GitHub (pinned to d036ad9781)