{"record":{"id":"c88b29f0c3b8aded","repo":"NationalSecurityAgency/ghidra","slug":"file-does-not-contain-got-instead","errorCode":null,"errorMessage":"file {} does not contain {}. got {} instead.","messagePattern":"file (.+?) does not contain (.+?)\\. got (.+?) instead\\.","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/data/OpenedDomainFile.java","lineNumber":45,"sourceCode":"\tpublic final T content;\n\n\tpublic static <T extends DomainObject> OpenedDomainFile<T> open(Class<T> contentType,\n\t\t\tDomainFile file, boolean okToUpgrade, boolean okToRecover, TaskMonitor monitor)\n\t\t\tthrows VersionException, CancelledException, IOException {\n\t\treturn new OpenedDomainFile<>(contentType, file, okToUpgrade, okToRecover, monitor);\n\t}\n\n\tpublic static <T extends DomainObject> OpenedDomainFile<T> open(Class<T> contentType,\n\t\t\tDomainFile file, TaskMonitor monitor)\n\t\t\tthrows VersionException, CancelledException, IOException {\n\t\treturn new OpenedDomainFile<>(contentType, file, false, false, monitor);\n\t}\n\n\tpublic OpenedDomainFile(Class<T> contentType, DomainFile file, boolean okToUpgrade,\n\t\t\tboolean okToRecover, TaskMonitor monitor)\n\t\t\tthrows VersionException, CancelledException, IOException {\n\t\tif (!contentType.isAssignableFrom(file.getDomainObjectClass())) {\n\t\t\tthrow new ClassCastException(\"file \" + file + \" does not contain \" + contentType +\n\t\t\t\t\". got \" + file.getDomainObjectClass() + \" instead.\");\n\t\t}\n\t\tcontent = contentType.cast(file.getDomainObject(this, okToUpgrade, okToRecover, monitor));\n\t}\n\n\t@Override\n\tpublic void close() {\n\t\tif (content != null) {\n\t\t\tcontent.release(this);\n\t\t}\n\t}\n}\n","sourceCodeStart":27,"sourceCodeEnd":58,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/data/OpenedDomainFile.java#L27-L58","documentation":"Thrown by the OpenedDomainFile constructor as a ClassCastException when the DomainFile's underlying domain object class is not assignable to the requested contentType. The caller asked to open a file as one DomainObject subtype (e.g. Program) but the file actually stores another (e.g. DataTypeManager or a different content type). The message reports the expected type and the actual class.","triggerScenarios":"Calling OpenedDomainFile.open(Program.class, file, monitor) on a file that is a ByteProvider/DataTypeArchive rather than a Program. Passing a DomainFile obtained from a project folder that holds non-program content. Requesting a subtype the file's class does not implement.","commonSituations":"Tooling that assumes all domain files are programs; opening a file selected from a mixed-type project folder; version/format mismatches where the domain object class resolved differently; passing the wrong class literal.","solutions":["Before opening, check file.getDomainObjectClass() and verify contentType.isAssignableFrom(it).","Pass the correct contentType matching what the file actually stores (inspect the file's content type metadata).","Branch on the file's content type and open with the appropriate class literal for each.","Guard UI/file-chooser flows to only offer files of the expected content type."],"exampleFix":"// before\ntry (OpenedDomainFile<Program> f = OpenedDomainFile.open(Program.class, file, monitor)) {\n  ... // throws if file is not a Program\n}\n\n// after\nClass<?> doc = file.getDomainObjectClass();\nif (!Program.class.isAssignableFrom(doc)) {\n  throw new IOException(\"File \" + file + \" is not a program; got \" + doc);\n}\ntry (OpenedDomainFile<Program> f = OpenedDomainFile.open(Program.class, file, monitor)) {\n  ...\n}","handlingStrategy":"validation","validationCode":"Class<?> doc = file.getDomainObjectClass();\nif (!contentType.isAssignableFrom(doc)) {\n  throw new IOException(\"File \" + file + \" stores \" + doc + \", not \" + contentType);\n}\nOpenedDomainFile.open(contentType, file, monitor);","typeGuard":null,"tryCatchPattern":"try {\n  return OpenedDomainFile.open(contentType, file, monitor);\n} catch (ClassCastException e) {\n  throw new IOException(\"Wrong content type for \" + file, e);\n}","preventionTips":["Inspect file.getDomainObjectClass() before opening.","Filter file choosers by the expected content type.","Branch on content type rather than assuming all files are Programs."],"tags":["ghidra","domain-file","type-mismatch","classcast"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}