{"record":{"id":"1a794054def220d1","repo":"TheAlgorithms/Java","slug":"key-key-not-found-in-the-table","errorCode":null,"errorMessage":"Key {key} not found in the table.","messagePattern":"Key (.+?) not found in the table\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java","lineNumber":164,"sourceCode":"        Integer wrappedInt = key;\n        int hash = hashFunction1(key);\n        if (isEmpty()) {\n            throw new IllegalArgumentException(\"Table is empty, cannot delete.\");\n        }\n\n        if (Objects.equals(buckets[hash], wrappedInt)) {\n            buckets[hash] = emptySlot;\n            size--;\n            return;\n        }\n\n        hash = hashFunction2(key);\n        if (Objects.equals(buckets[hash], wrappedInt)) {\n            buckets[hash] = emptySlot;\n            size--;\n            return;\n        }\n        throw new IllegalArgumentException(\"Key \" + key + \" not found in the table.\");\n    }\n\n    /**\n     * Displays the hash table contents, bucket by bucket.\n     */\n    public void displayHashtable() {\n        for (int i = 0; i < tableSize; i++) {\n            if ((buckets[i] == null) || Objects.equals(buckets[i], emptySlot)) {\n                System.out.println(\"Bucket \" + i + \": Empty\");\n            } else {\n                System.out.println(\"Bucket \" + i + \": \" + buckets[i].toString());\n            }\n        }\n        System.out.println();\n    }\n\n    /**\n     * Finds the index of a given key in the hash table.","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java#L146-L182","documentation":"Thrown by `HashMapCuckooHashing.deleteKeyFromHashTable` when the key is not found in either of its two cuckoo buckets (`hashFunction1` or `hashFunction2`). Cuckoo hashing guarantees a present key lives in one of exactly two slots, so absence in both means the key was never inserted (or was already deleted, its slot now `emptySlot`).","triggerScenarios":"Calling `deleteKeyFromHashTable(k)` for a `k` that was never inserted, or that was already deleted.","commonSituations":"Deleting a key from stale data; double-delete; deleting a key that was never there; retrying a delete that already succeeded.","solutions":["Verify the key exists with `checkTableContainsKey(k)` before deleting","Track which keys you inserted at the caller","Treat 'not found' as a no-op rather than an error at the call site"],"exampleFix":"// before\nmap.deleteKeyFromHashTable(k);\n// after\nif (map.checkTableContainsKey(k)) {\n    map.deleteKeyFromHashTable(k);\n}","handlingStrategy":"validation","validationCode":"if (map.checkTableContainsKey(key)) {\n    map.deleteKeyFromHashTable(key);\n}","typeGuard":null,"tryCatchPattern":"try {\n    map.deleteKeyFromHashTable(key);\n} catch (IllegalArgumentException e) {\n    // key not present\n}","preventionTips":["Guard deletes with a contains check","Avoid redundant/duplicate deletes"],"tags":["hashmap","cuckoo-hashing","not-found","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}