{"record":{"id":"e386dd52186de665","repo":"java-native-access/jna","slug":"component-must-be-visible","errorCode":null,"errorMessage":"Component must be visible","messagePattern":"Component must be visible","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":2554,"sourceCode":"            return getComponentID(w);\n        }\n        // Declaring the argument as Object rather than Component avoids class not\n        // found errors on phoneME foundation profile.\n        static long getComponentID(Object o) throws HeadlessException {\n            if (GraphicsEnvironment.isHeadless()) {\n                throw new HeadlessException(\"No native windows when headless\");\n            }\n            Component c = (Component)o;\n            if (c.isLightweight()) {\n                throw new IllegalArgumentException(\"Component must be heavyweight\");\n            }\n            if (!c.isDisplayable())\n                throw new IllegalStateException(\"Component must be displayable\");\n            // On X11 VMs prior to 1.5, the window must be visible\n            if (Platform.isX11()\n                && System.getProperty(\"java.version\").startsWith(\"1.4\")) {\n                if (!c.isVisible()) {\n                    throw new IllegalStateException(\"Component must be visible\");\n                }\n            }\n            // By this point, we're certain that Toolkit.loadLibraries() has\n            // been called, thus avoiding AWT/JAWT link errors\n            // (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6539705).\n            return Native.getWindowHandle0(c);\n        }\n    }\n}\n","sourceCodeStart":2536,"sourceCodeEnd":2564,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L2536-L2564","documentation":"Thrown by Native.getWindow(Component) on X11 Java 1.4 VMs when the component is not yet visible. In that old environment JNA requires the window to be actually visible before obtaining the native window handle, otherwise AWT/JAWT lookups fail.","triggerScenarios":"Calling Native.getWindow(c) on X11 with java.version starting with '1.4' while c.isVisible() is false (e.g. before setVisible(true) or while the frame is hidden).","commonSituations":"Legacy deployments on old X11 JVMs where automation scripts fetch window handles immediately after creating the frame without making it visible.","solutions":["Call frame.setVisible(true) before Native.getWindow(c)","Upgrade the JVM; this restriction only applies to 1.4-era X11 VMs","Guard the call with if (c.isVisible())"],"exampleFix":"// before\nlong hwnd = Native.getWindow(frame);\n// after\nframe.setVisible(true);\nlong hwnd = Native.getWindow(frame);","handlingStrategy":"validation","validationCode":"if (Platform.isX11() && c != null && !c.isVisible()) {\n    frame.setVisible(true); // or defer the call\n}\nlong hwnd = Native.getWindow(c);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always make the window visible before requesting its handle","On X11 avoid Java 1.4-era JVMs; upgrade the runtime"],"tags":["jna","awt","x11","visibility","legacy-jvm"],"backgroundTag":"invalid-state-transition","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}