{"record":{"id":"c36d187b08019a2d","repo":"mission-peace/interview","slug":"duplicate-date","errorCode":null,"errorMessage":"Duplicate date ","messagePattern":"Duplicate date ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/interview/tree/RedBlackTree.java","lineNumber":190,"sourceCode":"        } else {\n            return false;\n        }\n    }\n\n    private Node insert(Node parent, Node root, int data) {\n        if(root  == null || root.isNullLeaf) {\n            //if parent is not null means tree is not empty\n            //so create a red leaf node\n            if(parent != null) {\n                return createRedNode(parent, data);\n            } else { //otherwise create a black root node if tree is empty\n                return createBlackNode(data);\n            }\n        }\n\n        //duplicate insertion is not allowed for this tree.\n        if(root.data == data) {\n            throw new IllegalArgumentException(\"Duplicate date \" + data);\n        }\n        //if we go on left side then isLeft will be true\n        //if we go on right side then isLeft will be false.\n        boolean isLeft;\n        if(root.data > data) {\n            Node left = insert(root, root.left, data);\n            //if left becomes root parent means rotation\n            //happened at lower level. So just return left\n            //so that nodes at upper level can set their\n            //child correctly\n            if(left == root.parent) {\n                return left;\n            }\n            //set the left child returned to be left of root node\n            root.left = left;\n            //set isLeft to be true\n            isLeft = true;\n        } else {","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/mission-peace/interview/blob/94be5deb0c0df30ade2a569cf3056b7cc1e012f4/src/com/interview/tree/RedBlackTree.java#L172-L208","documentation":"RedBlackTree.insert does not allow duplicate keys; when the descent reaches a node whose data equals the value being inserted it throws IllegalArgumentException(\"Duplicate date \" + data). This is a deliberate invariant of this tree implementation rather than an accidental bug (note the 'date' typo in the message).","triggerScenarios":"Calling insert(data) with a value already present in the tree, including the initial insert(root, data) call and recursive insert(root, node, data) descents.","commonSituations":"Loading a dataset with repeated keys (e.g. duplicate dates in a time-series index), re-inserting an already processed record, or retry logic that replays an insert without checking membership.","solutions":["Check search(data) != null before calling insert and skip/update instead of re-inserting","Deduplicate the input collection before bulk loading into the tree","Catch IllegalArgumentException around insert if duplicates should be silently ignored"],"exampleFix":"// before\ntree.insert(date);\n// after\nif (tree.search(date) == null) {\n    tree.insert(date);\n}","handlingStrategy":"try-catch","validationCode":"if (tree.search(data) != null) { /* already present, skip */ } else { tree.insert(data); }","typeGuard":null,"tryCatchPattern":"try {\n    tree.insert(data);\n} catch (IllegalArgumentException e) {\n    // duplicate key, ignore or update\n}","preventionTips":["Deduplicate input collections before tree insertion","Check membership with search() before inserting","Remember duplicates are unsupported in this RedBlackTree; use a multimap variant if needed"],"tags":["java","tree","duplicate-key"],"backgroundTag":"duplicate-key","analyzedSha":"94be5deb0c0df30ade2a569cf3056b7cc1e012f4","analyzedAt":"2026-09-08T13:27:05.954Z","contentChangedAt":"2026-09-08T13:27:05.954Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}