{"record":{"id":"2f43295e3826ce00","repo":"apache/dolphinscheduler","slug":"invalid-key-format","errorCode":null,"errorMessage":"Invalid key format","messagePattern":"Invalid key format","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/DependentItem.java","lineNumber":49,"sourceCode":"    private long depTaskCode;\n    private String cycle;\n    private String dateValue;\n    private DependResult dependResult;\n    private Boolean parameterPassing = false;\n\n    public String getKey() {\n        return String.format(\"%d-%d-%s-%s\",\n                getDefinitionCode(),\n                getDepTaskCode(),\n                getCycle(),\n                getDateValue());\n    }\n\n    public DependentItem fromKey(String key) {\n        String[] parts = key.split(\"-\");\n        boolean isNegativeDepTaskCode = parts.length == 5 && parts[1].isEmpty();\n        if (parts.length != 4 && !isNegativeDepTaskCode) {\n            throw new IllegalArgumentException(\"Invalid key format\");\n        }\n        int offset = isNegativeDepTaskCode ? 1 : 0;\n        setDefinitionCode(Long.parseLong(parts[0]));\n        setDepTaskCode(Long.parseLong(isNegativeDepTaskCode ? \"-\" + parts[2] : parts[1]));\n        setCycle(parts[2 + offset]);\n        setDateValue(parts[3 + offset]);\n        return this;\n    }\n\n}\n","sourceCodeStart":31,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/model/DependentItem.java#L31-L60","documentation":"DependentItem.fromKey parses a composite dependent-item key expected to have 4 dash-separated parts (definitionCode, depTaskCode, cycle, dateValue). Because task codes are unsigned longs, a negative dependency task code adds an extra empty part, giving 5 parts with an empty parts[1]. If the key splits into neither 4 parts nor that 5-part negative pattern, an IllegalArgumentException('Invalid key format') is thrown.","triggerScenarios":"Calling fromKey with a key that has fewer than 4 segments, more than 5, or 5 segments whose parts[1] is not empty (e.g. double dash in the wrong place, trailing dash, or a malformed code containing a dash). Any dependent-item key that was not produced by the matching toKey serialization.","commonSituations":"Manually constructed or hand-edited dependency keys in the DB/API payload; keys built by an older/newer version with a different separator; keys where a task code itself was corrupted; copy-paste dropping or duplicating a segment.","solutions":["Log the offending key and count its '-' separators; fix the producer so it emits exactly 4 segments (or 5 with empty second segment for negative codes).","Ensure the key is generated by DependentItem's own toKey/serialization rather than string concatenation elsewhere.","Check for negative task codes: they serialize with a leading '-' producing the 5-part form; only that exact shape is accepted.","Validate keys at API/DB ingestion time before they reach fromKey.","If parsing external input, catch IllegalArgumentException and reject the payload with a clear message."],"exampleFix":"// before\nString key = definitionCode + \"-\" + depTaskCode + \"-\" + cycle + \"-\" + dateValue; // breaks on negative depTaskCode? no—but manual joins break\n// after\nDependentItem item = new DependentItem().fromKey(item.toKey()); // always round-trip via the canonical serializer","handlingStrategy":"validation","validationCode":"static boolean isValidItemKey(String key) {\n    String[] p = key.split(\"-\", -1);\n    return p.length == 4 || (p.length == 5 && p[1].isEmpty());\n}","typeGuard":"boolean isParsableKey(String key) { return key != null && isValidItemKey(key); }","tryCatchPattern":"try { item.fromKey(key); } catch (IllegalArgumentException e) { throw new BadRequestException(\"malformed dependent item key: \" + key); }","preventionTips":["Only build keys via the canonical toKey serializer","Reject malformed keys at API ingestion with a 400","Never hand-edit dependency keys in the DB","Add a round-trip test toKey()->fromKey() for negative task codes"],"tags":["parsing","format-validation","dependent-task"],"backgroundTag":"invalid-argument-format","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}