NationalSecurityAgency/ghidra · error · SQLException
attempted to drop non-BSim database
Error message
attempted to drop non-BSim database
What it means
Thrown as an SQLException by H2FileFunctionDatabase.dropDatabase() when the database file exists and is connectable, but its schema does not contain the expected BSim tables (keyvaluetable, desctable, weighttable). This is a safety guard that prevents dropping a non-BSim H2 file that happens to live at the same path.
Source
Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2FileFunctionDatabase.java:152
// ignore request and return
return;
}
// Connect to database and examine schema
HashSet<String> tableNames = new HashSet<>();
try (Connection c = initConnection(); Statement st = c.createStatement()) {
try (ResultSet rs = st.executeQuery(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name")) {
while (rs.next()) {
tableNames.add(rs.getString(1));
}
}
}
// Spot check for a few BSim table names that always exist
if (!tableNames.contains("keyvaluetable") || !tableNames.contains("desctable") ||
!tableNames.contains("weighttable")) {
throw new SQLException("attempted to drop non-BSim database");
}
fileDs.dispose(); // disconnect before deleting database
BSimServerInfo serverInfo = fileDs.getServerInfo();
if (!fileDs.delete()) {
throw new SQLException("failed to delete H2-file database: " + serverInfo);
}
Msg.info(this, "Deleted BSim H2-file database: " + serverInfo);
}
/**
* Create vector map which maps vector ID to {@link VectorStoreEntry}
* @return vector map
* @throws SQLException if error occurs while reading map data
*/View on GitHub (pinned to d5f144c24d)
Solutions
- Verify the target file is actually a BSim H2 database by checking for the expected tables.
- If the database is a partial/failed creation, manually delete the file rather than using dropDatabase().
- Ensure the correct BSim URL is being used for the drop operation.
- If the file is genuinely not a BSim database, do not attempt to drop it via BSim APIs.
Example fix
// before
db.dropDatabase(); // throws if tables missing
// after
if (!isBsimDatabase(fileDs)) {
// manually clean up non-BSim or partial file
Files.deleteIfExists(dbPath);
} else {
db.dropDatabase();
} Defensive patterns
Strategy: validation
Validate before calling
// Verify the H2 file is a BSim database before dropping
Set<String> bsimTables = Set.of("keyvaluetable", "desctable", "weighttable");
try (Connection c = fileDs.getConnection(); Statement st = c.createStatement();
ResultSet rs = st.executeQuery(
"SELECT table_name FROM information_schema.tables WHERE table_schema='public'")) {
Set<String> found = new HashSet<>();
while (rs.next()) found.add(rs.getString(1));
if (!found.containsAll(bsimTables)) {
throw new IllegalStateException(
"Not a BSim database; missing tables: " + Sets.difference(bsimTables, found));
}
} Try / catch
try {
database.dropDatabase();
} catch (SQLException e) {
if (e.getMessage().equals("attempted to drop non-BSim database")) {
// This is not a BSim DB; if it's a stale partial, delete manually
if (forceDeleteNonBsim) {
Files.deleteIfExists(dbPath);
} else {
showErrorDialog("Not a BSim Database",
"The file is not a valid BSim database and will not be dropped.");
}
} else {
throw e;
}
} Prevention
- Validate the H2 file contains BSim tables before calling dropDatabase().
- Use distinct file paths/names for BSim databases to avoid collisions with other H2 files.
- If a previous createDatabase failed partially, clean up the file manually rather than via dropDatabase().
- Never point BSim operations at arbitrary H2 files.
When it happens
Trigger: Occurs when the information_schema query returns table names but the three mandatory BSim tables are absent. This happens when: the H2 file at the path is a different application's database, a partially-created BSim database that failed before all tables were written, or a file that was manually modified or replaced.
Common situations: Pointing a BSim drop command at an arbitrary H2 file. A previous createDatabase call failed partway through, leaving an incomplete schema. The file path collides with another tool's H2 database.
Related errors
- database in use
- failed to delete H2-file database: {}
- Missing databaseName for drop database
- attempted to drop non-BSim database
- Database does not exist: {}
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/f8248e05f319f2a8.
Report an issue: GitHub.