{"record":{"id":"e8ff76e35e2bbff7","repo":"doocs/leetcode","slug":"invalid-char-e8ff76","errorCode":null,"errorMessage":"Invalid char: ","messagePattern":"Invalid char: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"solution/0400-0499/0488.Zuma Game/README.md","lineNumber":301,"sourceCode":"        }\n\n        long stateBits = 0;\n        for (char ch : stateChars) {\n            stateBits = (stateBits << 3) | Zuma.encode(ch);\n        }\n        return stateBits;\n    }\n\n    private static long encode(char ch) {\n        return switch (ch) {\n            case 'R' -> 0x1;\n            case 'G' -> 0x2;\n            case 'B' -> 0x3;\n            case 'W' -> 0x4;\n            case 'Y' -> 0x5;\n            case ' ' -> 0x0;\n            default  ->\n                throw new IllegalArgumentException(\"Invalid char: \" + ch);\n        };\n    }\n}\n```\n\n<!-- tabs:end -->\n\n<!-- solution:end -->\n\n<!-- problem:end -->\n","sourceCodeStart":283,"sourceCodeEnd":312,"githubUrl":"https://github.com/doocs/leetcode/blob/f84f361dc403a65c4c031f6e0774297cc377f00a/solution/0400-0499/0488.Zuma Game/README.md#L283-L312","documentation":"This is the Java Zuma Game encode() switch inside the Chinese README for LeetCode 488. Characters are mapped R->0x1, G->0x2, B->0x3, W->0x4, Y->0x5, space->0x0; the default branch throws IllegalArgumentException naming the offending character. It documents that any input outside [RGBYW ] is a programming error, not a runtime condition to recover from.","triggerScenarios":"Compiling the README snippet and calling encode with lowercase letters, punctuation, or whitespace other than plain space (tabs, CR/LF from file reads).","commonSituations":"Following the tutorial with hand-typed input that includes a typo or wrong case; reading boards from files without trim(); extending the solution to more colors but forgetting the encoder; mixed full-width characters from CJK input methods.","solutions":["Normalize input first: s = s.trim().toUpperCase() and filter to [RGBYW]","Extend the switch when adding new colors to the game","Validate with a character whitelist loop or regex before encoding","Check the exception message — it prints the exact char that failed"],"exampleFix":"// before\nencode(\"RgB\"); // throws Invalid char: g\n\n// after\nencode(\"RgB\".toUpperCase()); // ok","handlingStrategy":"validation","validationCode":"String s2 = s.trim().toUpperCase();\nif (!s2.matches(\"[RGBYW ]*\")) throw new IllegalArgumentException(\"Invalid char in: \" + s2);","typeGuard":"private static boolean isValidBoardChar(char c) { return \"RGBYW \".indexOf(c) >= 0; }","tryCatchPattern":"try { encode(input); } catch (IllegalArgumentException e) { /* message names the bad char; sanitize input and retry */ }","preventionTips":["Uppercase and trim tutorial inputs","Avoid copy-paste of invisible characters","Keep the switch in sync with new colors"],"tags":["java","validation","illegal-argument","encoding","documentation"],"backgroundTag":"invalid-input-character","analyzedSha":"f84f361dc403a65c4c031f6e0774297cc377f00a","analyzedAt":"2026-08-27T04:29:31.522Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}