{"record":{"id":"e43c355c71bbb1c1","repo":"java-native-access/jna","slug":"can-t-parse-array-content-type-not-supported-vartype","errorCode":null,"errorMessage":"Can't parse array content - type not supported: <vartype>","messagePattern":"Can't parse array content - type not supported: <vartype>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java","lineNumber":742,"sourceCode":"                case VT_UNKNOWN:\n                    hr = OleAuto.INSTANCE.SafeArrayPutElement(this, paramIndices, ((Unknown) arg).getPointer());\n                    COMUtils.checkRC(hr);\n                    break;\n                case VT_DISPATCH:\n                    hr = OleAuto.INSTANCE.SafeArrayPutElement(this, paramIndices, ((Dispatch) arg).getPointer());\n                    COMUtils.checkRC(hr);\n                    break;\n                case VT_CY:\n                    hr = OleAuto.INSTANCE.SafeArrayPutElement(this, paramIndices, ((CURRENCY) arg).getPointer());\n                    COMUtils.checkRC(hr);\n                    break;\n                case VT_DECIMAL:\n                    hr = OleAuto.INSTANCE.SafeArrayPutElement(this, paramIndices, ((DECIMAL) arg).getPointer());\n                    COMUtils.checkRC(hr);\n                    break;\n                case VT_RECORD:\n                default:\n                    throw new IllegalStateException(\"Can't parse array content - type not supported: \" + getVarType().intValue());\n            }\n        }\n\n        /**\n         * Retrieve the value at the referenced index from the SAFEARRAY.\n         *\n         * <p>The function creates a copy of the value. The values are\n         * allocated with native functions and need to be freed accordingly.</p>\n         *\n         * @param indices the index, order follows java/C convention\n         * @return the variant\n         */\n        public Object getElement(int... indices) {\n            WinDef.LONG[] paramIndices = new WinDef.LONG[indices.length];\n            for (int i = 0; i < indices.length; i++) {\n                paramIndices[i] = new WinDef.LONG(indices[indices.length - i - 1]);\n            }\n","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java#L724-L760","documentation":"OaIdl.SAFEARRAY's putElement/variant-setting switch only supports specific VARTYPEs (e.g. VT_I4, VT_BSTR, VT_DECIMAL, ...). VT_RECORD and any unrecognized variant type fall into `default` and throw an IllegalStateException naming the vartype.","triggerScenarios":"Calling SafeArrayPutElement (via SAFEARRAY.putElement or OleAuto) on a SAFEARRAY whose declared varType is VT_RECORD or otherwise unhandled by the switch.","commonSituations":"Interoperating with COM type libraries that define record-containing safe arrays; arrays created elsewhere (e.g. VB) with record or user-defined types; version differences where newer VT kinds are unsupported.","solutions":["Inspect getVarType() of the SAFEARRAY before writing and handle only supported element types","Unpack VT_RECORD elements manually into supported primitives or a UDT-compliant structure","Wrap the array in a Variant and use Variant.VARIANT-based APIs that support records","Extend/patch the switch in a local fork to support the needed VARTYPE"],"exampleFix":"// before\nsafeArray.putElement(indices, recordValue); // VT_RECORD -> IllegalStateException\n// after\nif (safeArray.getVarType().intValue() == VAREnum.VT_RECORD) {\n    // serialize record fields into supported element types instead\n} else {\n    safeArray.putElement(indices, recordValue);\n}","handlingStrategy":"type-guard","validationCode":"int vt = safeArray.getVarType().intValue();\nboolean writable = vt != VAREnum.VT_RECORD && SUPPORTED_VARTYPES.contains(vt);","typeGuard":"boolean isSupportedVartype(int vt) {\n    switch (vt) {\n        case VAREnum.VT_I2: case VAREnum.VT_I4: case VAREnum.VT_R4:\n        case VAREnum.VT_R8: case VAREnum.VT_BSTR: case VAREnum.VT_BOOL:\n        case VAREnum.VT_DECIMAL: case VAREnum.VT_UI1: return true;\n        default: return false;\n    }\n}","tryCatchPattern":"try {\n    safeArray.putElement(indices, value);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"type not supported\")) { /* custom write path */ }\n    else throw e;\n}","preventionTips":["Check getVarType() before every putElement on foreign arrays","Avoid VT_RECORD safe arrays or handle them with dedicated record APIs","Keep JNA updated; new VARTYPE support is added over time","Document the vartypes your COM interop layer supports"],"tags":["com","safearray","vartype","unsupported-type"],"backgroundTag":"unsupported-enum-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"}