{"record":{"id":"ddaf46f7489d51f5","repo":"java-native-access/jna","slug":"supplied-array-has-no-dimensions","errorCode":null,"errorMessage":"Supplied Array has no dimensions.","messagePattern":"Supplied Array has no dimensions\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/OaIdlUtil.java","lineNumber":125,"sourceCode":"            int dimensions = sa.getDimensionCount();\n            int[] elements = new int[dimensions];\n            int[] cumElements = new int[dimensions];\n            int varType = sa.getVarType().intValue();\n\n            for (int i = 0; i < dimensions; i++) {\n                elements[i] = sa.getUBound(i) - sa.getLBound(i) + 1;\n            }\n\n            for (int i = dimensions - 1; i >= 0; i--) {\n                if (i == (dimensions - 1)) {\n                    cumElements[i] = 1;\n                } else {\n                    cumElements[i] = cumElements[i + 1] * elements[i + 1];\n                }\n            }\n\n            if (dimensions == 0) {\n                throw new IllegalArgumentException(\"Supplied Array has no dimensions.\");\n            }\n\n            int elementCount = cumElements[0] * elements[0];\n\n            Object sourceArray;\n            switch (varType) {\n                case VT_UI1:\n                case VT_I1:\n                    sourceArray = dataPointer.getByteArray(0, elementCount);\n                    break;\n                case VT_BOOL:\n                case VT_UI2:\n                case VT_I2:\n                    sourceArray = dataPointer.getShortArray(0, elementCount);\n                    break;\n                case VT_UI4:\n                case VT_UINT:\n                case VT_I4:","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/OaIdlUtil.java#L107-L143","documentation":"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.'","triggerScenarios":"Calling OaIdlUtil.toPrimitiveArray on a SAFEARRAY created with cDims==0, an uninitialized/unallocated array, or one whose SafeArrayGetDim/rgsabound lookups yield no dimensions.","commonSituations":"Receiving an empty SAFEARRAY from a COM server; passing a default-constructed SAFEARRAY; an array whose descriptor was never initialized via SafeArrayCreate.","solutions":["Verify the SAFEARRAY was created via SafeArrayCreate with cDims >= 1 before conversion","Check dimensions via safeArray.getVarType()/SafeArrayGetLBound, UBound or the array's rgsabound before calling","Guard the call: skip conversion when the COM method can legitimately return an empty array","Handle the IllegalArgumentException as an 'empty array' signal"],"exampleFix":"// before\nObject[] result = OaIdlUtil.toPrimitiveArray(safeArray);\n// after\nif (safeArray == null || safeArray.getDimensionCount() == 0) {\n    Object[] result = new Object[0];\n} else {\n    Object[] result = OaIdlUtil.toPrimitiveArray(safeArray);\n}","handlingStrategy":"validation","validationCode":"boolean hasDims = safeArray != null && safeArray.getDimensionCount() > 0; // skip conversion when false\n","typeGuard":"boolean isConvertible(OaIdl.SAFEARRAY sa) { return sa != null && sa.getVarType() != null; }","tryCatchPattern":"try {\n    Object[] r = OaIdlUtil.toPrimitiveArray(sa);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"no dimensions\")) return new Object[0];\n    throw e;\n}","preventionTips":["Verify the COM producer always returns a dimensioned SAFEARRAY","Guard against empty/uninitialized arrays from COM calls","Treat zero-dimension arrays as empty results rather than errors","Check SafeArrayGetDim output before bulk conversion"],"tags":["com","safearray","empty-array","invalid-argument"],"backgroundTag":"empty-required-field","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}