java-native-access/jna · error · UnsupportedOperationException

No support (yet) for " + System.getProperty("os.name")

Error message

No support (yet) for " + System.getProperty("os.name")

What it means

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.

Source

Thrown at contrib/platform/src/com/sun/jna/platform/KeyboardUtils.java:56

 *
 * @author twall
 */
// TODO: key clicks
// TODO: auto-repeat
// TODO: keyboard bell
// TODO: led state
public class KeyboardUtils {
    static final NativeKeyboardUtils INSTANCE;
    static {
        if (GraphicsEnvironment.isHeadless()) {
            throw new HeadlessException("KeyboardUtils requires a keyboard");
        }
        if (Platform.isWindows()) {
            INSTANCE = new W32KeyboardUtils();
        }
        else if (Platform.isMac()) {
            INSTANCE = new MacKeyboardUtils();
            throw new UnsupportedOperationException("No support (yet) for "
                                                    + System.getProperty("os.name"));
        }
        else {
            INSTANCE = new X11KeyboardUtils();
        }
    }

    public static boolean isPressed(int keycode, int location) {
        return INSTANCE.isPressed(keycode, location);
    }
    public static boolean isPressed(int keycode) {
        return INSTANCE.isPressed(keycode);
    }

    private static abstract class NativeKeyboardUtils {
        public abstract boolean isPressed(int keycode, int location);
        public boolean isPressed(int keycode) {
            return isPressed(keycode, KeyEvent.KEY_LOCATION_UNKNOWN);

View on GitHub (pinned to d036ad9781)

Solutions

  1. Only use KeyboardUtils on Windows or macOS; gate with Platform.isWindows()/Platform.isMac()
  2. Use a pure-Java input polling approach on Linux (e.g. JNativeHook)
  3. Catch ExceptionInInitializerError/UnsupportedOperationException at first reference and degrade gracefully

Example fix

// before
KeyboardUtils.isPressed(code);
// after
if (!(Platform.isWindows() || Platform.isMac())) {
    logger.warn("KeyboardUtils unsupported on " + System.getProperty("os.name"));
    return;
}
KeyboardUtils.isPressed(code);
Defensive patterns

Strategy: validation

Validate before calling

if (!(Platform.isWindows() || Platform.isMac())) {
    throw new UnsupportedOperationException("KeyboardUtils unsupported on " + System.getProperty("os.name"));
}

Type guard

boolean keyboardUtilsSupported() {
    return Platform.isWindows() || Platform.isMac();
}

Try / catch

try {
    KeyboardUtils.isPressed(keycode);
} catch (Throwable t) {
    // fall back to JNativeHook or other input polling
}

Prevention

When it happens

Trigger: Loading KeyboardUtils on Linux/BSD/Solaris (anything not Windows or Mac) as written in this code branch — message includes os.name.

Common situations: Running the library on Linux or in Docker (Linux-based) containers; unusual JVM os.name values on exotic platforms.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/92fa0e82cab1ed5e. Report an issue: GitHub.