{"record":{"id":"fc2075e3e5fcd9e4","repo":"apache/seatunnel","slug":"sparse-vector-value-must-be-a-number-but-got-s","errorCode":null,"errorMessage":"Sparse vector value must be a Number, but got: %s","messagePattern":"Sparse vector value must be a Number, but got: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/VectorUtils.java","lineNumber":164,"sourceCode":"            int index = (Integer) key;\n            if (index < 0) {\n                throw new IllegalArgumentException(\n                        String.format(\"Sparse vector index cannot be negative: %d\", index));\n            }\n            // prevent OOM\n            if (index > 1000000) {\n                throw new IllegalArgumentException(\n                        String.format(\"Sparse vector index too large: %d\", index));\n            }\n            maxIndex = Math.max(maxIndex, index);\n        }\n        Float[] denseVector = new Float[maxIndex + 1];\n        Arrays.fill(denseVector, 0.0f);\n        for (Map.Entry<?, ?> entry : sparseVector.entrySet()) {\n            Object key = entry.getKey();\n            Object value = entry.getValue();\n            if (!(value instanceof Number)) {\n                throw new IllegalArgumentException(\n                        String.format(\n                                \"Sparse vector value must be a Number, but got: %s\",\n                                value.getClass().getName()));\n            }\n            int index = (Integer) key;\n            denseVector[index] = ((Number) value).floatValue();\n        }\n        return denseVector;\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/VectorUtils.java#L146-L175","documentation":"convertSparseVectorToFloatArray requires every value in the sparse vector map to be a java.lang.Number so it can call floatValue(). This IllegalArgumentException is thrown when a value is some other type, naming the offending value's class.","triggerScenarios":"Passing a Map<?, ?> whose values are Strings, boxed-but-stringified decimals, or arbitrary objects instead of numeric types; typically when the sparse vector comes from deserialized JSON/config where numbers became strings.","commonSituations":"Parsing sparse vectors from JSON where floats were serialized as strings ('0.5'), building vectors from raw config maps (Typesafe Config returns heterogeneous types), or schema drift in an upstream producer.","solutions":["Inspect the logged class name and convert values to a numeric type before the call (e.g. Float.parseFloat(str)).","Fix the deserialization layer so numbers stay numeric (use a JSON mapper that infers number types).","Ensure the map is typed Map<Integer, ? extends Number> at the call site.","Pre-validate all values with instanceof Number and reject/convert non-numeric entries."],"exampleFix":"// before\nMap<String, String> raw = Map.of(\"0\", \"0.5\");\nFloat[] dense = VectorUtils.convertSparseVectorToFloatArray(raw); // throws\n// after\nMap<Integer, Float> v = raw.entrySet().stream()\n    .collect(Collectors.toMap(e -> Integer.parseInt(e.getKey()), e -> Float.parseFloat(e.getValue())));\nFloat[] dense2 = VectorUtils.convertSparseVectorToFloatArray(v);","handlingStrategy":"type-guard","validationCode":"boolean allNumeric(Map<?,?> v) { return v.values().stream().allMatch(x -> x instanceof Number); }","typeGuard":"boolean isNumber(Object o) { return o instanceof Number; }","tryCatchPattern":"try { Float[] d = VectorUtils.convertSparseVectorToFloatArray(v); } catch (IllegalArgumentException e) { /* convert value types per the message and retry */ }","preventionTips":["Type maps as Map<Integer, ? extends Number>","Ensure JSON deserialization preserves numeric types","Convert string numbers explicitly before the call"],"tags":["vector","sparse-vector","type-mismatch","java"],"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"}