{"record":{"id":"d3d6463d754670ea","repo":"java-native-access/jna","slug":"cannot-get-desktop-names-properties-net-desktop-names-or-win","errorCode":null,"errorMessage":"Cannot get desktop names properties (_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)","messagePattern":"Cannot get desktop names properties \\(_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES\\)","errorType":"exception","errorClass":"X11Exception","httpStatus":null,"severity":"error","filePath":"contrib/x11/src/jnacontrib/x11/api/X.java","lineNumber":280,"sourceCode":"            return cur_desktop;\n        }\n\n        /**\n         * Returns the available desktops.\n         *\n         * @return available desktops\n         * @throws X11Exception thrown if X11 window errors occurred\n         */\n        public Desktop[] getDesktops() throws X11Exception {\n            Window root = getRootWindow();\n            String[] desktopNames;\n            try {\n                desktopNames = root.getUtf8ListProperty(getAtom(\"UTF8_STRING\"), \"_NET_DESKTOP_NAMES\");\n            } catch (X11Exception e) {\n                try {\n                    desktopNames = root.getStringListProperty(X11.XA_STRING, \"_WIN_WORKSPACE_NAMES\");\n                } catch (X11Exception e1) {\n                    throw new X11Exception(\"Cannot get desktop names properties (_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)\");\n                }\n            }\n\n            Desktop[] desktops = new Desktop[getDesktopCount()];\n            for (int i = 0; i < desktops.length; i++) {\n                desktops[i] = new Desktop(this, i, desktopNames[i]);\n            }\n\n            return desktops;\n        }\n\n        /**\n         * Switches to the given desktop.\n         *\n         * @param nr desktop number\n         * @throws X11Exception thrown if X11 window errors occurred\n         */\n        public void switchDesktop(int nr) throws X11Exception {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/x11/src/jnacontrib/x11/api/X.java#L262-L298","documentation":"X.getDesktops() reads desktop name lists from the root window: first the EWMH UTF8 property _NET_DESKTOP_NAMES, falling back to _WIN_WORKSPACE_NAMES. If both list-property reads throw X11Exception, this combined X11Exception is thrown, meaning desktop names cannot be resolved. Note the error is also reachable later: getDesktopCount() may succeed but produce a count larger than desktopNames.length, causing an ArrayIndexOutOfBoundsException when building Desktop objects.","triggerScenarios":"Calling X.getDesktops() when neither _NET_DESKTOP_NAMES nor _WIN_WORKSPACE_NAMES is set on the root window; also when desktop count > number of names, indexing desktopNames[i] out of bounds.","commonSituations":"Minimal WMs that set the count atom but no name atoms, bare Xvfb, mismatch between _NET_NUMBER_OF_DESKTOPS and the name list length after a WM restart.","solutions":["Run a WM that publishes _NET_DESKTOP_NAMES (GNOME/KDE/XFCE)","Check xprop -root _NET_DESKTOP_NAMES returns data","Catch X11Exception and synthesize default names (\"Desktop 1\", \"Desktop 2\", ...) based on getDesktopCount()","Guard desktopNames[i] against index >= length and use an empty placeholder name"],"exampleFix":"// before\nDesktop[] desktops = x.getDesktops();\n// after\nDesktop[] desktops;\ntry {\n    desktops = x.getDesktops();\n} catch (X11Exception e) {\n    desktops = new Desktop[0]; // or generate default names\n}","handlingStrategy":"fallback","validationCode":"Process p = Runtime.getRuntime().exec(new String[]{\"xprop\",\"-root\",\"_NET_DESKTOP_NAMES\"});\nboolean namesAvailable = p.waitFor() == 0;","typeGuard":null,"tryCatchPattern":"try {\n    desktops = x.getDesktops();\n} catch (X11Exception e) {\n    // synthesize defaults\n    int n = 1;\n    try { n = x.getDesktopCount(); } catch (X11Exception ignored) {}\n    desktops = new Desktop[n == 0 ? 1 : n];\n}","preventionTips":["Use a WM that publishes _NET_DESKTOP_NAMES","Guard name-list length against desktop count when building UI","Catch X11Exception and generate placeholder names","Avoid combining count and name reads in one non-failing path"],"tags":["x11","window-manager","ewmh","property-missing"],"backgroundTag":"resource-not-found","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"}