NationalSecurityAgency/ghidra · error · ClassCastException
file {} does not contain {}. got {} instead.
Error message
file {} does not contain {}. got {} instead. What it means
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.
Source
Thrown at Ghidra/Debug/ProposedUtils/src/main/java/ghidra/framework/data/OpenedDomainFile.java:45
public final T content;
public static <T extends DomainObject> OpenedDomainFile<T> open(Class<T> contentType,
DomainFile file, boolean okToUpgrade, boolean okToRecover, TaskMonitor monitor)
throws VersionException, CancelledException, IOException {
return new OpenedDomainFile<>(contentType, file, okToUpgrade, okToRecover, monitor);
}
public static <T extends DomainObject> OpenedDomainFile<T> open(Class<T> contentType,
DomainFile file, TaskMonitor monitor)
throws VersionException, CancelledException, IOException {
return new OpenedDomainFile<>(contentType, file, false, false, monitor);
}
public OpenedDomainFile(Class<T> contentType, DomainFile file, boolean okToUpgrade,
boolean okToRecover, TaskMonitor monitor)
throws VersionException, CancelledException, IOException {
if (!contentType.isAssignableFrom(file.getDomainObjectClass())) {
throw new ClassCastException("file " + file + " does not contain " + contentType +
". got " + file.getDomainObjectClass() + " instead.");
}
content = contentType.cast(file.getDomainObject(this, okToUpgrade, okToRecover, monitor));
}
@Override
public void close() {
if (content != null) {
content.release(this);
}
}
}
View on GitHub (pinned to d5f144c24d)
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.
Example fix
// before
try (OpenedDomainFile<Program> f = OpenedDomainFile.open(Program.class, file, monitor)) {
... // throws if file is not a Program
}
// after
Class<?> doc = file.getDomainObjectClass();
if (!Program.class.isAssignableFrom(doc)) {
throw new IOException("File " + file + " is not a program; got " + doc);
}
try (OpenedDomainFile<Program> f = OpenedDomainFile.open(Program.class, file, monitor)) {
...
} Defensive patterns
Strategy: validation
Validate before calling
Class<?> doc = file.getDomainObjectClass();
if (!contentType.isAssignableFrom(doc)) {
throw new IOException("File " + file + " stores " + doc + ", not " + contentType);
}
OpenedDomainFile.open(contentType, file, monitor); Try / catch
try {
return OpenedDomainFile.open(contentType, file, monitor);
} catch (ClassCastException e) {
throw new IOException("Wrong content type for " + file, e);
} Prevention
- Inspect file.getDomainObjectClass() before opening.
- Filter file choosers by the expected content type.
- Branch on content type rather than assuming all files are Programs.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- only DBTrace files are supported
- Value '{address}' does not evaluate to an int
- File does not correspond to Program content: {}
- Property ${propertyName} is not object type
- Cannot convert register value: ({class}) '{val}'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/c88b29f0c3b8aded.
Report an issue: GitHub.