java-native-access/jna · error · IllegalArgumentException

Supplied Array has no dimensions.

Error message

Supplied Array has no dimensions.

What it means

OaIdlUtil.toPrimitiveArray computes dimension/element counts from the SAFEARRAY's bounds; if the array reports zero dimensions, there is nothing to convert and it throws IllegalArgumentException 'Supplied Array has no dimensions.'

Solutions

  1. Verify the SAFEARRAY was created via SafeArrayCreate with cDims >= 1 before conversion
  2. Check dimensions via safeArray.getVarType()/SafeArrayGetLBound, UBound or the array's rgsabound before calling
  3. Guard the call: skip conversion when the COM method can legitimately return an empty array
  4. Handle the IllegalArgumentException as an 'empty array' signal

Example fix

// before
Object[] result = OaIdlUtil.toPrimitiveArray(safeArray);
// after
if (safeArray == null || safeArray.getDimensionCount() == 0) {
    Object[] result = new Object[0];
} else {
    Object[] result = OaIdlUtil.toPrimitiveArray(safeArray);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasDims = safeArray != null && safeArray.getDimensionCount() > 0; // skip conversion when false

Type guard

boolean isConvertible(OaIdl.SAFEARRAY sa) { return sa != null && sa.getVarType() != null; }

Try / catch

try {
    Object[] r = OaIdlUtil.toPrimitiveArray(sa);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("no dimensions")) return new Object[0];
    throw e;
}

Prevention

When it happens

Trigger: Calling OaIdlUtil.toPrimitiveArray on a SAFEARRAY created with cDims==0, an uninitialized/unallocated array, or one whose SafeArrayGetDim/rgsabound lookups yield no dimensions.

Common situations: Receiving an empty SAFEARRAY from a COM server; passing a default-constructed SAFEARRAY; an array whose descriptor was never initialized via SafeArrayCreate.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/ddaf46f7489d51f5. Report an issue: GitHub.

Appendix: source

Thrown at contrib/platform/src/com/sun/jna/platform/win32/OaIdlUtil.java:125

            int dimensions = sa.getDimensionCount();
            int[] elements = new int[dimensions];
            int[] cumElements = new int[dimensions];
            int varType = sa.getVarType().intValue();

            for (int i = 0; i < dimensions; i++) {
                elements[i] = sa.getUBound(i) - sa.getLBound(i) + 1;
            }

            for (int i = dimensions - 1; i >= 0; i--) {
                if (i == (dimensions - 1)) {
                    cumElements[i] = 1;
                } else {
                    cumElements[i] = cumElements[i + 1] * elements[i + 1];
                }
            }

            if (dimensions == 0) {
                throw new IllegalArgumentException("Supplied Array has no dimensions.");
            }

            int elementCount = cumElements[0] * elements[0];

            Object sourceArray;
            switch (varType) {
                case VT_UI1:
                case VT_I1:
                    sourceArray = dataPointer.getByteArray(0, elementCount);
                    break;
                case VT_BOOL:
                case VT_UI2:
                case VT_I2:
                    sourceArray = dataPointer.getShortArray(0, elementCount);
                    break;
                case VT_UI4:
                case VT_UINT:
                case VT_I4:

View on GitHub (pinned to d036ad9781)