{"record":{"id":"5a195fca1af06892","repo":"NationalSecurityAgency/ghidra","slug":"headless-use-not-supported","errorCode":null,"errorMessage":"headless use not supported","messagePattern":"headless use not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Features/Base/ghidra_scripts/FindDataTypeConflictCauseScript.java","lineNumber":43,"sourceCode":"import ghidra.framework.plugintool.PluginTool;\nimport ghidra.program.database.data.DataTypeUtilities;\nimport ghidra.program.model.data.*;\nimport ghidra.program.model.data.Enum;\n\npublic class FindDataTypeConflictCauseScript extends GhidraScript {\n\n\tprivate DataTypeManager dtm;\n\tprivate HashSet<Integer> previouslyDetectedPairHashes;\n\tprivate boolean hasReport;\n\n\t@Override\n\tprotected void run() throws Exception {\n\n\t\tpreviouslyDetectedPairHashes = new HashSet<>();\n\n\t\tPluginTool tool = state.getTool();\n\t\tif (tool == null) {\n\t\t\tthrow new UnsupportedOperationException(\"headless use not supported\");\n\t\t}\n\n\t\tDataTypeManagerService dtmService = tool.getService(DataTypeManagerService.class);\n\t\tif (dtmService == null) {\n\t\t\tpopup(\"Tool does not contain a DataTypeManagerService!\");\n\t\t\treturn;\n\t\t}\n\n\t\tList<DataType> selectedDatatypes = dtmService.getSelectedDatatypes();\n\t\tif (selectedDatatypes.size() != 1) {\n\t\t\tpopup(\"Select a single conflict datatype before running script\");\n\t\t\treturn;\n\t\t}\n\n\t\tDataType selectedDt = DataTypeUtilities.getBaseDataType(selectedDatatypes.get(0));\n\t\tif (selectedDt == null) {\n\t\t\tpopup(\"Selected datatype must not be a default Pointer\");\n\t\t\treturn;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/Base/ghidra_scripts/FindDataTypeConflictCauseScript.java#L25-L61","documentation":"Thrown by FindDataTypeConflictCauseScript.run when state.getTool() returns null, i.e. the script is executed in headless mode. The script needs the GUI PluginTool to obtain the DataTypeManagerService and the user's currently selected datatype, neither of which exists without a headed tool.","triggerScenarios":"Invoking FindDataTypeConflictCauseScript via analyzeHeadless, the headless analyzer, or any non-GHG script environment where there is no PluginTool. Also if run from a context where the script state was constructed without a tool.","commonSituations":"Trying to batch-run this interactive diagnostic in a headless pipeline. Running from a script that constructs GhidraScript state manually without a tool. Misconfiguring a headless script runner.","solutions":["Run FindDataTypeConflictCauseScript inside the GUI CodeBrowser tool, not headless.","If you need headless conflict analysis, write a custom script that iterates datatypes directly via the program's DataTypeManager instead of relying on the service.","Check `state.getTool() != null` before calling and exit gracefully with a message."],"exampleFix":"// before\nPluginTool tool = state.getTool();\nif (tool == null) {\n    throw new UnsupportedOperationException(\"headless use not supported\");\n}\n\n// after\nPluginTool tool = state.getTool();\nif (tool == null) {\n    println(\"This script requires the GUI CodeBrowser tool.\");\n    return;\n}","handlingStrategy":"validation","validationCode":"PluginTool tool = state.getTool();\nif (tool == null) {\n    println(\"FindDataTypeConflictCauseScript requires the GUI tool.\");\n    return;\n}","typeGuard":"boolean isHeadless(GhidraScript script) {\n    return script.getState().getTool() == null;\n}","tryCatchPattern":"try {\n    run();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().equals(\"headless use not supported\")) {\n        println(\"Run inside the CodeBrowser GUI tool.\");\n    } else throw e;\n}","preventionTips":["Run interactive diagnostic scripts in the GUI CodeBrowser tool.","Guard with `state.getTool() != null` and exit gracefully.","For headless pipelines, write a custom script that uses the program's DataTypeManager directly."],"tags":["script","headless","gui","datatype"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}