{"record":{"id":"cc2e3279d012b2f2","repo":"TheAlgorithms/Java","slug":"unexpected-value-choice","errorCode":null,"errorMessage":"Unexpected value: {choice}","messagePattern":"Unexpected value: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java","lineNumber":66,"sourceCode":"                scan.close();\n                return;\n\n            case 5:\n                System.out.println(\"Enter the Key to find and print:  \");\n                key = scan.nextInt();\n                System.out.println(\"Key: \" + key + \" is at index: \" + h.findKeyInTable(key) + \"\\n\");\n                break;\n\n            case 6:\n                System.out.printf(\"Load factor is: %.2f%n\", h.checkLoadFactor());\n                break;\n\n            case 7:\n                h.reHashTableIncreasesTableSize();\n                break;\n\n            default:\n                throw new IllegalArgumentException(\"Unexpected value: \" + choice);\n            }\n        }\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":71,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java#L48-L71","documentation":"Thrown by the default branch of the switch in MainCuckooHashing.main. The menu defines cases 1-7 (add, delete, print, exit, search, load factor, rehash); any other integer entered at the prompt reaches default and aborts. This is a defensive guard for invalid interactive input, not a library API contract.","triggerScenarios":"Typing 0, 8, 9, or any integer outside 1-7 at the 'Enter your Choice' prompt; an automated harness piping an unexpected int into stdin; adding a new menu item to the println list but forgetting the matching case.","commonSituations":"User typo at the console; test/automation feeding raw ints; menu/case drift after editing only one half of the switch.","solutions":["Enter an integer strictly in the range 1-7 at the prompt.","Add input validation (range check) before the switch and re-prompt on invalid input instead of throwing.","If a new feature was intended, add the corresponding case label and keep default as a true error path."],"exampleFix":"// before\ndefault:\n    throw new IllegalArgumentException(\"Unexpected value: \" + choice);\n\n// after\ndefault:\n    System.out.println(\"Invalid choice \" + choice + \"; please enter 1-7.\");\n    break;","handlingStrategy":"validation","validationCode":"// Validate menu input before the switch\nif (choice < 1 || choice > 7) {\n    System.out.println(\"Please enter a number between 1 and 7.\");\n    continue;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Range-check user input before dispatching to a switch.","Keep menu labels and case labels in sync when adding options.","Use an enum for menu options to make invalid values unrepresentable."],"tags":["cli","menu","switch-default","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}