java-native-access/jna · critical · UnsupportedOperationException

No support for " + os

Error message

No support for " + os

What it means

WindowUtils' static initializer creates the platform singleton: W32WindowUtils on Windows, X11WindowUtils on X11/Mac-style checks, and otherwise throws UnsupportedOperationException('No support for <os.name>'). This is a fail-fast at class load — the library genuinely has no window-utility implementation for the detected OS.

Source

Thrown at contrib/platform/src/com/sun/jna/platform/WindowUtils.java:745

         * 1.4/X11 implementation.
         */
        public static boolean requiresVisible;
        public static final NativeWindowUtils INSTANCE;
        static {
            if (Platform.isWindows()) {
                INSTANCE = new W32WindowUtils();
            }
            else if (Platform.isMac()) {
                INSTANCE = new MacWindowUtils();
            }
            else if (Platform.isX11()) {
                INSTANCE = new X11WindowUtils();
                requiresVisible = System.getProperty("java.version")
                                        .matches("^1\\.4\\..*");
            }
            else {
                String os = System.getProperty("os.name");
                throw new UnsupportedOperationException("No support for " + os);
            }
        }
    }

    private static NativeWindowUtils getInstance() {
        return Holder.INSTANCE;
    }

    private static class W32WindowUtils extends NativeWindowUtils {
        private HWND getHWnd(Component w) {
            HWND hwnd = new HWND();
            hwnd.setPointer(Native.getComponentPointer(w));
            return hwnd;
        }

        /**
         * W32 alpha will only work if <code>sun.java2d.noddraw</code>
         * is set

View on GitHub (pinned to d036ad9781)

Solutions

  1. Run on a supported OS: Windows, or Linux/X11 as expected by your JNA version.
  2. Upgrade contrib/platform / JNA version — newer releases may recognize your platform (e.g. newer Mac handling via X11).
  3. Check os.name handling: ensure the JVM's os.name is not overridden unexpectedly (-Dos.name=...).
  4. Wrap first WindowUtils use in try-catch for UnsupportedOperationException to fail gracefully on unsupported OSes.
  5. Provide your own NativeWindowUtils subclass and avoid the platform singleton.

Example fix

// before
WindowUtils.setWindowMask(frame, area); // throws on macOS in old JNA
// after
if (Platform.isWindows() || Platform.isX11()) {
    WindowUtils.setWindowMask(frame, area);
} else {
    // fall back to non-shaped window
}
Defensive patterns

Strategy: try-catch

Validate before calling

String os = System.getProperty("os.name");
boolean supported = os != null && (os.contains("Windows") || os.contains("Linux") || os.contains("SunOS") || os.contains("FreeBSD"));

Try / catch

try { WindowUtils.setWindowAlpha(w, 0.8f); } catch (UnsupportedOperationException e) { // platform unsupported, skip window effects }

Prevention

When it happens

Trigger: Any first use of WindowUtils (WindowUtils.getInstance, setWindowAlpha, setWindowMask, getAllWindows, etc.) on an OS whose os.name is neither Windows nor matches the X11 branch — e.g. macOS under a JNA version with no Mac handling, or exotic platforms.

Common situations: Deploying Swing window-shape/transparency features to macOS on an older JNA; exotic embedded Linux without X11 properties detected; misreported os.name via -Djava.vendor/-Dos.name overrides; trying to use WindowUtils in a headless server environment.

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/d2367cd37b38d9c8. Report an issue: GitHub.