{"record":{"id":"5cd12c63f6ce5192","repo":"NationalSecurityAgency/ghidra","slug":"optional-table-does-not-exist-when-it-should","errorCode":null,"errorMessage":"Optional table does not exist when it should: ","messagePattern":"Optional table does not exist when it should: ","errorType":"exception","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/TableScoreCaching.java","lineNumber":211,"sourceCode":"\t}\n\n\t@Override\n\tpublic void resetStorage(double simThresh, double sigThresh) throws LSHException {\n\t\tsimThreshold = simThresh;\n\t\tsigThreshold = sigThresh;\n\t\tcacheMap = new TreeMap<String, Float>();\t\t\t\t// Clear the cache\n\t\tQueryOptionalExist query = new QueryOptionalExist();\n\t\tquery.tableName = TABLE_NAME;\n\t\tquery.keyType = Types.VARCHAR;\n\t\tquery.valueType = Types.REAL;\n\t\tquery.attemptCreation = false;\n\t\tquery.clearTable = true;\t\t\t\t\t\t\t\t// Clear out the table\n\t\tResponseOptionalExist response = query.execute(db);\n\t\tif (response == null) {\n\t\t\tthrow new LSHException(db.getLastError().message);\n\t\t}\n\t\tif (!response.tableExists) {\n\t\t\tthrow new LSHException(\"Optional table does not exist when it should: \" + TABLE_NAME);\n\t\t}\n\t\tsetUpInsert(2);\n\t\tinsertValue.keys[0] = SIMILARITY_KEY;\n\t\tinsertValue.keys[1] = SIGNIFICANCE_KEY;\n\t\tinsertValue.values[0] = Float.valueOf((float) simThreshold);\t\t// Write thresholds to special table rows\n\t\tinsertValue.values[1] = Float.valueOf((float) sigThreshold);\n\t\tif (insertValue.execute(db) == null) {\n\t\t\tthrow new LSHException(\"Unable to initialize new thresholds: \" + TABLE_NAME);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":193,"sourceCodeEnd":224,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/TableScoreCaching.java#L193-L224","documentation":"Thrown by TableScoreCaching during threshold re-initialization when QueryOptionalExist reports the optional score table does not exist (response.tableExists is false) even though clearTable=true was requested. This is an internal consistency failure: the code assumed the optional table was already created but the database does not contain it. It indicates the database was never fully initialized or the optional table was dropped externally.","triggerScenarios":"Calling the threshold-reset/initialize path on a TableScoreCaching whose backing SQL BSim database lacks the optional score table. Triggered when setThresholds() or equivalent is invoked before the table has ever been created, or after a manual DROP of the optional table. The query sets attemptCreation=false, so it will not auto-create.","commonSituations":"Database created with an older BSim schema version that did not include the optional score table. Manual schema surgery that removed the table. A fresh database that was never initialized via the full creation path (which would set attemptCreation=true). Version mismatch between BSim client and the on-disk database schema.","solutions":["Run the full BSim database initialization that creates all optional tables (use the creation path with attemptCreation=true) before setting thresholds.","Upgrade the database schema to the current BSim version so all optional tables exist.","Check database version metadata and re-create the database if the optional table is missing.","Avoid manually dropping BSim internal tables; use the supported admin/maintenance commands."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check the database has the optional score table before initializing thresholds.\nboolean hasOptionalTable = bsimDatabase.hasOptionalTable(TableScoreCaching.TABLE_NAME);\nif (!hasOptionalTable) {\n    bsimDatabase.initializeOptionalTables(); // full creation path with attemptCreation=true\n}","typeGuard":null,"tryCatchPattern":"try {\n    scoreCaching.setThresholds(sim, sig);\n} catch (LSHException e) {\n    if (e.getMessage().contains(\"Optional table does not exist\")) {\n        bsimDatabase.initializeOptionalTables();\n        scoreCaching.setThresholds(sim, sig); // retry after creation\n    } else throw e;\n}","preventionTips":["Always initialize a BSim database via the full creation path before use.","Do not manually drop BSim internal optional tables.","Verify database schema version matches the client before operations."],"tags":["bsim","database","schema","optional-table","lsh-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}