{"record":{"id":"3a109e7d722168df","repo":"java-native-access/jna","slug":"invalid-type-of-prop-name-property","errorCode":null,"errorMessage":"Invalid type of <prop_name> property","messagePattern":"Invalid type of <prop_name> property","errorType":"exception","errorClass":"X11Exception","httpStatus":null,"severity":"error","filePath":"contrib/x11/src/jnacontrib/x11/api/X.java","lineNumber":1043,"sourceCode":"                //the specified property does not exist for the specified window\n                return null;\n            }\n\n            if( xa_ret_type == null ){\n                //the specified property does not exist for the specified window\n                return null;\n            }\n\n            if( xa_ret_type == null ){\n                //the specified property does not exist for the specified window\n                return null;\n            }\n\n            if (xa_ret_type == null || xa_prop_type == null ||\n                    !xa_ret_type.toNative().equals(xa_prop_type.toNative())) {\n                x11.XFree(ret_prop);\n                String prop_name = x11.XGetAtomName(display.x11Display, xa_prop_name);\n                throw new X11Exception(\"Invalid type of \" + prop_name + \" property\");\n            }\n\n            int ret_format = ret_format_ref.getValue();\n            long ret_nitems = ret_nitems_ref.getValue().longValue();\n\n            // null terminate the result to make string handling easier\n            int nbytes;\n            if (ret_format == 32)\n                nbytes = Native.LONG_SIZE;\n            else if (ret_format == 16)\n                nbytes = Native.LONG_SIZE / 2;\n            else if (ret_format == 8)\n                nbytes = 1;\n            else if (ret_format == 0)\n                nbytes = 0;\n            else\n                throw new X11Exception(\"Invalid return format\");\n            int length = Math.min((int) ret_nitems * nbytes, MAX_PROPERTY_VALUE_LEN);","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/x11/src/jnacontrib/x11/api/X.java#L1025-L1061","documentation":"After XGetWindowProperty returns, Window.getProperty checks that the returned type atom matches the requested type (comparing native atom values). If the property exists but holds a different type than requested (or either atom is null), it frees the returned buffer and throws \"Invalid type of <prop_name> property\".","triggerScenarios":"Requesting XA_CARDINAL for a property stored as XA_WINDOW or XA_ATOM (e.g. reading _NET_WM_PID variants or client-list with the wrong expected type); mixing EWMH and WinWM property types.","commonSituations":"Code copied between properties with different types (CARDINAL vs WINDOW vs STRING), window managers storing hints with nonstandard types, or passing a null/unresolved atom as xa_prop_type.","solutions":["Match the requested type to what the WM actually stores: run xprop -root <NAME> and read the TYPE line","For window-id lists use XA_WINDOW/XA_ATOM as appropriate instead of XA_CARDINAL","Handle the fallback path: if _NET_* typed read fails, try the _WIN_* equivalent with its own type","Catch X11Exception and retry with the alternate type"],"exampleFix":"// before\nlong[] pids = root.getIntProperty(X11.XA_CARDINAL, \"_NET_CLIENT_LIST\");\n// after\nlong[] ids;\ntry {\n    ids = root.getIntProperty(X11.XA_WINDOW, \"_NET_CLIENT_LIST\"); // client list holds WINDOW ids, not CARDINAL\n} catch (X11Exception e) {\n    ids = new long[0];\n}","handlingStrategy":"validation","validationCode":"// verify stored type matches what you request\n// xprop -root _NET_CLIENT_LIST  ->  TYPE = WINDOW, not CARDINAL","typeGuard":"boolean typeMatches(X11.Atom actual, X11.Atom expected) {\n    return actual != null && expected != null\n        && actual.toNative().equals(expected.toNative());\n}","tryCatchPattern":"try {\n    value = win.getIntProperty(X11.XA_CARDINAL, atom);\n} catch (X11Exception e) {\n    if (e.getMessage().startsWith(\"Invalid type\")) {\n        value = win.getIntProperty(X11.XA_WINDOW, atom); // retry with real type\n    } else throw e;\n}","preventionTips":["Check each property's stored TYPE with xprop before coding against it","Don't assume CARDINAL for all hints; window lists use WINDOW/ATOM types","Try _NET_* and _WIN_* variants with their own declared types","Keep a small atom->type map for the properties you use"],"tags":["x11","type-mismatch","property","xatom"],"backgroundTag":"type-mismatch","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}