{"record":{"id":"21c6ef0abb0c239e","repo":"alibaba/DataX","slug":"transformer-run-exception-21c6ef","errorCode":"TRANSFORMER_RUN_EXCEPTION","errorMessage":"dx_substr startIndex(%s) out of range(%s)","messagePattern":"dx_substr startIndex\\((.+?)\\) out of range\\((.+?)\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/datax/core/transport/transformer/SubstrTransformer.java","lineNumber":50,"sourceCode":"            columnIndex = (Integer) paras[0];\n            startIndex = Integer.valueOf((String) paras[1]);\n            length = Integer.valueOf((String) paras[2]);\n\n        } catch (Exception e) {\n            throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_ILLEGAL_PARAMETER, \"paras:\" + Arrays.asList(paras).toString() + \" => \" + e.getMessage());\n        }\n\n        Column column = record.getColumn(columnIndex);\n\n        try {\n            String oriValue = column.asString();\n            //如果字段为空，跳过subStr处理\n            if(oriValue == null){\n                return record;\n            }\n            String newValue;\n            if (startIndex > oriValue.length()) {\n                throw new RuntimeException(String.format(\"dx_substr startIndex(%s) out of range(%s)\", startIndex, oriValue.length()));\n            }\n            if (startIndex + length >= oriValue.length()) {\n                newValue = oriValue.substring(startIndex, oriValue.length());\n            } else {\n                newValue = oriValue.substring(startIndex, startIndex + length);\n            }\n\n            record.setColumn(columnIndex, new StringColumn(newValue));\n\n        } catch (Exception e) {\n            throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_RUN_EXCEPTION, e.getMessage(),e);\n        }\n        return record;\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":66,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/core/src/main/java/com/alibaba/datax/core/transport/transformer/SubstrTransformer.java#L32-L66","documentation":"Thrown by dx_substr when startIndex is greater than the length of the column's string value, since substring cannot start past the end. The check is per record after column.asString() (null values skip processing), so it fires only on rows whose value is shorter than startIndex, wrapped as TRANSFORMER_RUN_EXCEPTION.","triggerScenarios":"A row where the target column holds a string shorter than startIndex, e.g. startIndex=4 against \"abc\". startIndex == length is tolerated (yields empty string); only strictly greater throws.","commonSituations":"Source data whose column widths vary (free-text fields, codes of differing lengths), a startIndex tuned to one schema and reused against another, or trailing-whitespace trimming upstream that shortens values unexpectedly.","solutions":["Reduce startIndex to be <= the minimum non-null string length observed in the column.","Chain dx_pad before dx_substr to guarantee a minimum length, or use startIndex 0 when the intent is 'from the beginning'.","Find the offending row in the DataX task log (record contents are printed with the error) and validate the parameter against real data."],"exampleFix":"// before: value \"abc\", startIndex 4\n\"paras\": [1, \"4\", \"2\"]\n// after\n\"paras\": [1, \"0\", \"2\"]","handlingStrategy":"validation","validationCode":"String v = record.getColumn(idx).asString();\nif (v != null && startIndex > v.length()) startIndex = 0; // or clamp to v.length() for empty result","typeGuard":null,"tryCatchPattern":"catch DataXException(TRANSFORMER_RUN_EXCEPTION): quarantine the record with its raw value for later repair instead of failing the channel.","preventionTips":["Verify MIN(string length) >= startIndex on production data, not samples.","Prefer startIndex 0 + length when the intent is a fixed prefix extraction."],"tags":["datax","transformer","dx-substr","data-dependent"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}