{"record":{"id":"92fa0e82cab1ed5e","repo":"java-native-access/jna","slug":"no-support-yet-for-system-getproperty-os-name","errorCode":null,"errorMessage":"No support (yet) for \" + System.getProperty(\"os.name\")","messagePattern":"No support \\(yet\\) for \" \\+ System\\.getProperty\\(\"os\\.name\"\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/KeyboardUtils.java","lineNumber":56,"sourceCode":" *\n * @author twall\n */\n// TODO: key clicks\n// TODO: auto-repeat\n// TODO: keyboard bell\n// TODO: led state\npublic class KeyboardUtils {\n    static final NativeKeyboardUtils INSTANCE;\n    static {\n        if (GraphicsEnvironment.isHeadless()) {\n            throw new HeadlessException(\"KeyboardUtils requires a keyboard\");\n        }\n        if (Platform.isWindows()) {\n            INSTANCE = new W32KeyboardUtils();\n        }\n        else if (Platform.isMac()) {\n            INSTANCE = new MacKeyboardUtils();\n            throw new UnsupportedOperationException(\"No support (yet) for \"\n                                                    + System.getProperty(\"os.name\"));\n        }\n        else {\n            INSTANCE = new X11KeyboardUtils();\n        }\n    }\n\n    public static boolean isPressed(int keycode, int location) {\n        return INSTANCE.isPressed(keycode, location);\n    }\n    public static boolean isPressed(int keycode) {\n        return INSTANCE.isPressed(keycode);\n    }\n\n    private static abstract class NativeKeyboardUtils {\n        public abstract boolean isPressed(int keycode, int location);\n        public boolean isPressed(int keycode) {\n            return isPressed(keycode, KeyEvent.KEY_LOCATION_UNKNOWN);","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/KeyboardUtils.java#L38-L74","documentation":"KeyboardUtils' static initializer throws UnsupportedOperationException when the OS is neither Windows nor macOS, and the intended path here throws for unsupported operating systems. This blocks use of the keyboard utilities on platforms without a dedicated implementation.","triggerScenarios":"Loading KeyboardUtils on Linux/BSD/Solaris (anything not Windows or Mac) as written in this code branch — message includes os.name.","commonSituations":"Running the library on Linux or in Docker (Linux-based) containers; unusual JVM os.name values on exotic platforms.","solutions":["Only use KeyboardUtils on Windows or macOS; gate with Platform.isWindows()/Platform.isMac()","Use a pure-Java input polling approach on Linux (e.g. JNativeHook)","Catch ExceptionInInitializerError/UnsupportedOperationException at first reference and degrade gracefully"],"exampleFix":"// before\nKeyboardUtils.isPressed(code);\n// after\nif (!(Platform.isWindows() || Platform.isMac())) {\n    logger.warn(\"KeyboardUtils unsupported on \" + System.getProperty(\"os.name\"));\n    return;\n}\nKeyboardUtils.isPressed(code);","handlingStrategy":"validation","validationCode":"if (!(Platform.isWindows() || Platform.isMac())) {\n    throw new UnsupportedOperationException(\"KeyboardUtils unsupported on \" + System.getProperty(\"os.name\"));\n}","typeGuard":"boolean keyboardUtilsSupported() {\n    return Platform.isWindows() || Platform.isMac();\n}","tryCatchPattern":"try {\n    KeyboardUtils.isPressed(keycode);\n} catch (Throwable t) {\n    // fall back to JNativeHook or other input polling\n}","preventionTips":["Gate KeyboardUtils behind OS checks at startup","Use JNativeHook on Linux for keyboard polling","Test os.name-dependent code on all target platforms"],"tags":["java","platform","keyboard","unsupported"],"backgroundTag":"unsupported-platform","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}