{"record":{"id":"424b4717dbf26a74","repo":"openjdk/jdk","slug":"failed-to-retrieve-atom-name","errorCode":null,"errorMessage":"Failed to retrieve atom name.","messagePattern":"Failed to retrieve atom name\\.","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c","lineNumber":1698,"sourceCode":"}\n\n/*\n * Class:     sun_awt_X11_XlibWrapper\n * Method:    XGetAtomName\n * Signature: (JJ)Ljava/lang/String;\n */\nJNIEXPORT jstring JNICALL\nJava_sun_awt_X11_XlibWrapper_XGetAtomName(JNIEnv *env, jclass clazz,\n                      jlong display, jlong atom)\n{\n    jstring string = NULL;\n    char* name;\n    AWT_CHECK_HAVE_LOCK_RETURN(NULL);\n    name = (char*) XGetAtomName((Display*)jlong_to_ptr(display), atom);\n\n    if (name == NULL) {\n        fprintf(stderr, \"Atom was %d\\n\", (int)atom);\n        JNU_ThrowNullPointerException(env, \"Failed to retrieve atom name.\");\n        return NULL;\n    }\n\n    string = (*env)->NewStringUTF(env, (const char *)name);\n\n    XFree(name);\n\n    return string;\n}\n\n/*\n * Class:     sun_awt_X11_XlibWrapper\n * Method:    XMaxRequestSize\n * Signature: (J)J\n */\nJNIEXPORT jlong JNICALL\nJava_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz,\n                         jlong display) {","sourceCodeStart":1680,"sourceCodeEnd":1716,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c#L1680-L1716","documentation":"XlibWrapper.XGetAtomName called XGetAtomName() and got NULL back — the X server does not know an atom with that numeric ID. The code prints 'Atom was <n>' to stderr and throws java.lang.NullPointerException('Failed to retrieve atom name.') to Java. Atoms exist only while the server keeps them; an unknown ID means the atom was never interned on this display or was created on a different server.","triggerScenarios":"Java_sun_awt_X11_XlibWrapper_XGetAtomName being invoked with an atom value that came from a stale/closed display, was read from a property of another client that has exited (its atoms may be unregistered), or is simply garbage (uninitialized long). Xlib APIs like XGetAtomName return NULL for never-interned IDs.","commonSituations":"Debugging tools that cache atom IDs across display reconnects (X restart, ssh -X reconnection); window-manager interactions where the WM exited and its private atoms vanished; passing XA_* predefined values works, but custom names misspelled when interning earlier. The NPE surfaces in X11-based AWT internals or XlibWrapper users.","solutions":["Do not cache atom IDs across connections: re-intern with XInternAtom (XAtom.get()/XlibWrapper.XInternAtom) per display/session","Validate the atom ID is nonzero and came from the same Display connection before calling XGetAtomName","Catch the NullPointerException at the call site and degrade gracefully (treat property/atom as absent)","Check for a stale DISPLAY / reconnected SSH X11 forwarding and restart the app against the current server"],"exampleFix":"// before\nString name = XlibWrapper.XGetAtomName(display, atom); // may NPE if atom unknown\n\n// after\nString name = null;\ntry {\n    name = XlibWrapper.XGetAtomName(display, atom);\n} catch (NullPointerException e) {\n    // atom not interned on this display — recover\n}","handlingStrategy":"try-catch","validationCode":"// intern the name instead of trusting a cached numeric atom id\nlong atom = XlibWrapper.XInternAtom(display, \"_MY_PROPERTY\", false); // creates-or-finds, never unknown","typeGuard":null,"tryCatchPattern":"String name;\ntry {\n    name = XlibWrapper.XGetAtomName(display, atom);\n} catch (NullPointerException npe) {\n    name = null; // atom not interned on this display — treat as absent\n}","preventionTips":["Never cache atom IDs across Display connections or X server restarts","Prefer XInternAtom over stored numeric values","Re-derive atoms after DISPLAY changes or X11 forwarding reconnects"],"tags":["x11","atom","awt","xlib","native","jni"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}