java-native-access/jna · error · X11Exception
Cannot get desktop names properties (_NET_DESKTOP_NAMES or _
Error message
Cannot get desktop names properties (_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)
What it means
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.
Source
Thrown at contrib/x11/src/jnacontrib/x11/api/X.java:280
return cur_desktop;
}
/**
* Returns the available desktops.
*
* @return available desktops
* @throws X11Exception thrown if X11 window errors occurred
*/
public Desktop[] getDesktops() throws X11Exception {
Window root = getRootWindow();
String[] desktopNames;
try {
desktopNames = root.getUtf8ListProperty(getAtom("UTF8_STRING"), "_NET_DESKTOP_NAMES");
} catch (X11Exception e) {
try {
desktopNames = root.getStringListProperty(X11.XA_STRING, "_WIN_WORKSPACE_NAMES");
} catch (X11Exception e1) {
throw new X11Exception("Cannot get desktop names properties (_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)");
}
}
Desktop[] desktops = new Desktop[getDesktopCount()];
for (int i = 0; i < desktops.length; i++) {
desktops[i] = new Desktop(this, i, desktopNames[i]);
}
return desktops;
}
/**
* Switches to the given desktop.
*
* @param nr desktop number
* @throws X11Exception thrown if X11 window errors occurred
*/
public void switchDesktop(int nr) throws X11Exception {View on GitHub (pinned to d036ad9781)
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
Example fix
// before
Desktop[] desktops = x.getDesktops();
// after
Desktop[] desktops;
try {
desktops = x.getDesktops();
} catch (X11Exception e) {
desktops = new Desktop[0]; // or generate default names
} Defensive patterns
Strategy: fallback
Validate before calling
Process p = Runtime.getRuntime().exec(new String[]{"xprop","-root","_NET_DESKTOP_NAMES"});
boolean namesAvailable = p.waitFor() == 0; Try / catch
try {
desktops = x.getDesktops();
} catch (X11Exception e) {
// synthesize defaults
int n = 1;
try { n = x.getDesktopCount(); } catch (X11Exception ignored) {}
desktops = new Desktop[n == 0 ? 1 : n];
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Cannot get number of desktops properties (_NET_NUMBER_OF_DES
- Cannot get current desktop properties (_NET_CURRENT_DESKTOP
- Cannot get window manager info properties. (_NET_SUPPORTING_
- Cannot get client list properties (_NET_CLIENT_LIST or _WIN_
- Cannot send <msg> event.
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/d3d6463d754670ea.
Report an issue: GitHub.