{"record":{"id":"12a06ca316010718","repo":"apache/seatunnel","slug":"cannot-convert-to-int","errorCode":null,"errorMessage":"Cannot convert to int: ","messagePattern":"Cannot convert to int: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java","lineNumber":287,"sourceCode":"        Map<Object, Object> result = Maps.newHashMap();\n        map.forEach(\n                (k, v) -> {\n                    int keyFieldId = type.fields().get(0).fieldId();\n                    int valueFieldId = type.fields().get(1).fieldId();\n                    result.put(\n                            convertValue(k, fromType, type.keyType(), keyFieldId, wrapper),\n                            convertValue(v, fromType, type.valueType(), valueFieldId, wrapper));\n                });\n        return result;\n    }\n\n    protected int convertInt(Object value) {\n        if (value instanceof Number) {\n            return ((Number) value).intValue();\n        } else if (value instanceof String) {\n            return Integer.parseInt((String) value);\n        }\n        throw new IllegalArgumentException(\"Cannot convert to int: \" + value.getClass().getName());\n    }\n\n    protected long convertLong(Object value) {\n        if (value instanceof Number) {\n            return ((Number) value).longValue();\n        } else if (value instanceof String) {\n            return Long.parseLong((String) value);\n        }\n        throw new IllegalArgumentException(\"Cannot convert to long: \" + value.getClass().getName());\n    }\n\n    protected float convertFloat(Object value) {\n        if (value instanceof Number) {\n            return ((Number) value).floatValue();\n        } else if (value instanceof String) {\n            return Float.parseFloat((String) value);\n        }\n        throw new IllegalArgumentException(","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java#L269-L305","documentation":"convertInt accepts only Number and String values; any other Java type (Boolean, byte[], BigDecimal-in-some-flows, Date, etc.) cannot be converted to an Iceberg int and IllegalArgumentException with the value's class name is thrown.","triggerScenarios":"convertValue targeting an Iceberg IntegerType field receives a value that is neither Number nor String, e.g. a Boolean or Date from upstream data.","commonSituations":"Schema mismatches where upstream passes booleans/dates into int columns; CSV/JSON parsers producing unexpected Java types (e.g. boolean for 0/1).","solutions":["Fix upstream data/types so int fields carry numeric values (or numeric strings).","Pre-cast the field in a transform (e.g. CAST(col AS INT)).","Change the Iceberg column type to match the actual data type.","Catch IllegalArgumentException and handle/redirect bad records."],"exampleFix":"// before\nrow.setField(0, true); // int field\n// after\nrow.setField(0, 1); // or cast boolean to int upstream","handlingStrategy":"type-guard","validationCode":"if (!(v instanceof Number) && !(v instanceof String)) { throw new IllegalArgumentException(\"int field expects Number/String, got \" + v.getClass()); }","typeGuard":"Integer safeToInt(Object v) { if (v instanceof Number) return ((Number) v).intValue(); if (v instanceof String) return Integer.valueOf((String) v); return null; }","tryCatchPattern":"try { value = convertInt(raw); } catch (IllegalArgumentException e) { log.warn(\"Bad int value: {}\", e.getMessage()); }","preventionTips":["Coerce booleans to 0/1 upstream","Use transform CAST to INT before sink","Verify column types in SeaTunnelRowType match Iceberg schema"],"tags":["iceberg","type-conversion","type-mismatch"],"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"}