{"record":{"id":"d3d08834aad46493","repo":"NationalSecurityAgency/ghidra","slug":"already-connected-d3d088","errorCode":null,"errorMessage":"Already connected","messagePattern":"Already connected","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-jpda/src/main/java/ghidra/dbg/jdi/rmi/jpda/JdiCommands.java","lineNumber":73,"sourceCode":" */\n\nclass State {\n\n\tpublic RmiClient client;\n\tpublic RmiTrace trace;\n\tRmiTransaction tx;\n\n\tpublic RmiClient requireClient() {\n\t\tif (client == null) {\n\t\t\tthrow new RuntimeException(\"Not connected\");\n\t\t}\n\t\treturn client;\n\t}\n\n\tpublic void requireNoClient() {\n\t\tif (client != null) {\n\t\t\tclient = null;\n\t\t\tthrow new RuntimeException(\"Already connected\");\n\t\t}\n\t}\n\n\tpublic void resetClient() {\n\t\tclient = null;\n\t\tresetTrace();\n\t}\n\n\tpublic RmiTrace requireTrace() {\n\t\tif (trace == null) {\n\t\t\tthrow new RuntimeException(\"No trace started\");\n\t\t}\n\t\treturn trace;\n\t}\n\n\tpublic void requireNoTrace() {\n\t\tif (trace != null) {\n\t\t\tthrow new RuntimeException(\"Trace already started\");","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-jpda/src/main/java/ghidra/dbg/jdi/rmi/jpda/JdiCommands.java#L55-L91","documentation":"RuntimeException('Already connected') thrown by State.requireNoClient() when client is already non-null. Notably the method first sets client = null and then throws, so a duplicate connect attempt both clears the existing connection and signals the error. It guards connect-style commands that expect a clean (disconnected) state.","triggerScenarios":"Calling a connect/setup command that routes through requireNoClient() while State.client is already set (a previous connect succeeded and was not disconnected).","commonSituations":"Issuing connect twice in a row; reconnecting without first disconnecting; a command sequence that assumes a fresh session but one is already live.","solutions":["Disconnect/reset the client (resetClient or the disconnect command) before issuing another connect.","Check state.client == null before attempting connect; if non-null, reuse the existing connection.","Be aware that hitting this error already nulled the prior client, so you must reconnect afterward."],"exampleFix":"// before\n// connect called again while already connected -> 'Already connected' AND client cleared\n\n// after\nif (state.client != null) {\n    state.resetClient(); // explicit disconnect first\n}\nconnect(...);","handlingStrategy":"validation","validationCode":"if (state.client != null) {\n    state.resetClient(); // disconnect cleanly before reconnecting\n}\nconnect(...);","typeGuard":null,"tryCatchPattern":"try {\n    state.requireNoClient();\n} catch (RuntimeException e) {\n    if (\"Already connected\".equals(e.getMessage())) {\n        // note: client was just nulled; must reconnect\n    }\n}","preventionTips":["Disconnect before reconnecting; do not call connect twice.","Check state.client == null before attempting connect.","Remember this guard nulls the client before throwing, so reconnect afterward."],"tags":["ghidra","jdi","jpda","state-machine","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}