{"record":{"id":"bb2793474d6ffdc0","repo":"java-native-access/jna","slug":"wrong-array-size","errorCode":null,"errorMessage":"Wrong array size !","messagePattern":"Wrong array size !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java","lineNumber":1839,"sourceCode":"\n        public ARRAYDESC(Pointer pointer) {\n            super(pointer);\n            this.read();\n        }\n\n        /**\n         * @param tdescElem\n         *            C type : TYPEDESC<br>\n         * @param cDims dimensions\n         * @param rgbounds\n         *            [size_is]<br>\n         *            C type : SAFEARRAYBOUND[1]\n         */\n        public ARRAYDESC(TYPEDESC tdescElem, short cDims, SAFEARRAYBOUND rgbounds[]) {\n            this.tdescElem = tdescElem;\n            this.cDims = cDims;\n            if (rgbounds.length != this.rgbounds.length)\n                throw new IllegalArgumentException(\"Wrong array size !\");\n            this.rgbounds = rgbounds;\n        }\n\n        public static class ByReference extends ARRAYDESC implements\n                Structure.ByReference {\n\n        };\n    }\n\n    @FieldOrder({\"pparamdescex\", \"wParamFlags\"})\n    public static class PARAMDESC extends Structure {\n        public static class ByReference extends PARAMDESC implements\n                Structure.ByReference {\n        }\n\n        // replaced PARAMDESCEX.ByReference with Pointer\n        // because of JNA 4 has a problem with ByReference\n        public Pointer pparamdescex;","sourceCodeStart":1821,"sourceCodeEnd":1857,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java#L1821-L1857","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nARRAYDESC d = new ARRAYDESC(tdesc, cDims, new SAFEARRAYBOUND[0]);\n// after\nSAFEARRAYBOUND[] bounds = (SAFEARRAYBOUND[]) new SAFEARRAYBOUND().toArray(1);\nbounds[0].lLbound = 0;\nbounds[0].cElements = 10;\nARRAYDESC d = new ARRAYDESC(tdesc, (short) 1, bounds);","handlingStrategy":"validation","validationCode":"if (rgbounds == null || rgbounds.length != 1) throw new IllegalArgumentException(\"ARRAYDESC expects exactly \" + 1 + \" bound(s)\");","typeGuard":null,"tryCatchPattern":"try {\n    new ARRAYDESC(tdescElem, cDims, rgbounds);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Wrong array size\")) { /* reallocate bounds array */ }\n    else throw e;\n}","preventionTips":["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"],"tags":["com","typedesc","arraydesc","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}