{"record":{"id":"2b38b2d1b4401eb6","repo":"java-native-access/jna","slug":"no-mapping-for-02x","errorCode":null,"errorMessage":"No mapping for %02x","messagePattern":"No mapping for %02x","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Win32VK.java","lineNumber":443,"sourceCode":"    private Win32VK(int code) {\n        this(code, 0);\n    }\n\n    /**\n     * This will return the first of the multiple VK constants mapped to the same\n     * value. First as defined in the order of the header file listing the\n     * constants.\n     *\n     * @param code the code value.\n     * @return the VK enum instance.\n     */\n    public static Win32VK fromValue(final int code) {\n        for (Win32VK vk : Win32VK.values()) {\n            if (vk.code == code) {\n                return vk;\n            }\n        }\n        throw new IllegalArgumentException(String.format(\"No mapping for %02x\", code));\n    }\n}","sourceCodeStart":425,"sourceCodeEnd":445,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Win32VK.java#L425-L445","documentation":"Win32VK.fromValue(int) scans the VK enum constants for a matching virtual-key code and throws this IllegalArgumentException when no constant matches. It is a strict lookup: any code not modeled by the enum (OEM-specific, vendor-extended, or reserved codes) is rejected.","triggerScenarios":"Calling Win32VK.fromValue with a virtual-key code absent from the enum — e.g. nonstandard OEM keys (0xA6–0xAC range gaps), vendor-defined codes, or raw keyboard scancodes mistakenly passed as VK codes.","commonSituations":"Parsing WM_KEYDOWN lParam into VK codes from unusual keyboards/layouts; international keyboard layouts producing codes not in the enum; passing 0 or garbage values from uninitialized message structures.","solutions":["Validate/sanitize the code before lookup; treat unmatched codes as unhandled keys rather than failures.","Wrap in try-catch and fall back to raw-code handling.","Upgrade the JNA version, which may add newer VK constants.","Verify you are passing a virtual-key code, not a scancode (scancode conversion requires MapVirtualKey)."],"exampleFix":"// before\nWin32VK vk = Win32VK.fromValue(code); // throws for unknown codes\n// after\nWin32VK vk;\ntry {\n    vk = Win32VK.fromValue(code);\n} catch (IllegalArgumentException e) {\n    vk = null; // handle unknown key via raw code\n}","handlingStrategy":"try-catch","validationCode":"if (code < 0 || code > 0xFF) throw new IllegalArgumentException(\"not a VK code: \" + code);","typeGuard":"static Win32VK tryFromValue(int code) {\n    try { return Win32VK.fromValue(code); }\n    catch (IllegalArgumentException e) { return null; }\n}","tryCatchPattern":"try {\n    Win32VK vk = Win32VK.fromValue(code);\n    handle(vk);\n} catch (IllegalArgumentException unknown) {\n    handleRawCode(code);\n}","preventionTips":["Distinguish VK codes from scancodes before lookup.","Default to raw-code handling for unmatched keys instead of failing.","Keep JNA updated for newer VK constants."],"tags":["windows","keyboard","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}