{"record":{"id":"ca4fbf32fe6582f6","repo":"apache/seatunnel","slug":"unsupported-convert-s-to-array-typedefine-s","errorCode":null,"errorMessage":"Unsupported convert %s to Array, typeDefine: %s","messagePattern":"Unsupported convert (.+?) to Array, typeDefine: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java","lineNumber":194,"sourceCode":"            return array;\n        }\n        if (value instanceof List) {\n            SeaTunnelDataType elementType = typeDefine.getElementType();\n\n            List<Object> list = (List<Object>) value;\n            int elements = list.size();\n            for (int i = 0; i < elements; i++) {\n                list.set(i, convert(elementType, list.get(i)));\n            }\n            return list.toArray();\n        }\n        if (value instanceof Set) {\n            SeaTunnelDataType elementType = typeDefine.getElementType();\n\n            return ((Set) value).stream().map(e -> convert(elementType, e)).toArray();\n        }\n\n        throw new UnsupportedOperationException(\n                \"Unsupported convert \" + value.getClass() + \" to Array, typeDefine: \" + typeDefine);\n    }\n\n    default SeaTunnelRow convertRow(T typeDefine, Column columnDefine, Object value)\n            throws UnsupportedOperationException {\n        return convertRow((SeaTunnelRowType) columnDefine.getDataType(), value);\n    }\n\n    default SeaTunnelRow convertRow(SeaTunnelRowType typeDefine, Object value)\n            throws UnsupportedOperationException {\n        if (value instanceof SeaTunnelRow) {\n            return (SeaTunnelRow) value;\n        }\n        if (value instanceof Collection) {\n            Collection collection = (Collection) value;\n            if (collection.size() != typeDefine.getTotalFields()) {\n                throw new IllegalArgumentException(\n                        \"The size of collection is not equal to the size of row type\");","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java#L176-L212","documentation":"The default convertArray implementation only converts Collection values (including Set) whose elements it can recursively convert; a value of any other class throws this UnsupportedOperationException. typeDefine (ArrayType) identifies the expected array element type. It means the object on the ARRAY conversion path is not a Collection.","triggerScenarios":"Calling convertArray(...) or convert(...) with an ARRAY SqlType column when value is a Java array (e.g. int[], Object[]), an Iterable that is not a Collection, or an iterator/POJO.","commonSituations":"JDBC drivers returning native SQL arrays (java.sql.Array or primitive arrays) instead of Collections; passing a raw Object[] from a legacy API; forgetting that the converter handles Set/List but not arrays.","solutions":["Convert the array to a List first with java.util.Arrays.asList(...) or a stream before calling the converter.","If value is java.sql.Array, call getArray() and wrap the result in a List.","Override convertArray in a custom converter to handle primitive/native array types.","Check that the column SqlType ARRAY and its element type match the actual data."],"exampleFix":"// before\nconverter.convertArray(arrayType, jdbcArray.getArray()); // Object[]\n// after\nObject[] raw = (Object[]) jdbcArray.getArray();\nconverter.convertArray(arrayType, Arrays.asList(raw));","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Collection)) {\n    if (value != null && value.getClass().isArray()) {\n        value = Arrays.asList((Object[]) value); // normalize first\n    } else {\n        throw new IllegalArgumentException(\"convertArray expects a Collection, got \" + value.getClass());\n    }\n}","typeGuard":"boolean isCollectionOrArray(Object v) { return v instanceof Collection || (v != null && v.getClass().isArray()); }","tryCatchPattern":"try {\n    return converter.convertArray(arrayType, value);\n} catch (UnsupportedOperationException e) {\n    LOG.warn(\"Array conversion failed: {}\", e.getMessage());\n    return new Object[0];\n}","preventionTips":["Convert native arrays with Arrays.asList before calling the converter.","Unwrap java.sql.Array with getArray().","Remember the converter handles Collection/Set but not raw arrays or Iterable-only types.","Verify ArrayType element type matches element classes."],"tags":["type-mismatch","array-conversion","seatunnel-api"],"backgroundTag":"type-mismatch","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}