{"record":{"id":"c3a6bda7278e7b97","repo":"NationalSecurityAgency/ghidra","slug":"weighttable-has-wrong-number-of-rows","errorCode":null,"errorMessage":"weighttable has wrong number of rows","messagePattern":"weighttable has wrong number of rows","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/tables/WeightTable.java","lineNumber":77,"sourceCode":"\n\t/**\n\t * \n\t * @param factory the weight factory\n\t * @throws SQLException if there is an error creating/executing the query\n\t */\n\tpublic void recoverWeights(WeightFactory factory) throws SQLException {\n\t\ttry (Statement st = db.createStatement();\n\t\t\t\tResultSet rs = st.executeQuery(\"SELECT all * FROM weighttable\")) {\n\t\t\tdouble vals[] = new double[factory.getIDFSize() + factory.getTFSize() + 7];\n\t\t\tint numrows = 0;\n\t\t\twhile (rs.next()) {\n\t\t\t\tint id = rs.getInt(1);\n\t\t\t\tdouble val = rs.getDouble(2);\n\t\t\t\tvals[id] = val;\n\t\t\t\tnumrows += 1;\n\t\t\t}\n\t\t\tif (numrows != factory.getIDFSize() + factory.getTFSize() + 7) {\n\t\t\t\tthrow new SQLException(\"weighttable has wrong number of rows\");\n\t\t\t}\n\n\t\t\tfactory.set(vals);\n\t\t}\n\t}\n}\n","sourceCodeStart":59,"sourceCodeEnd":84,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/tables/WeightTable.java#L59-L84","documentation":"Thrown by WeightTable.recoverWeights when the number of rows read from the weighttable does not equal the expected size (IDF size + TF size + 7). The weighttable holds precomputed term-frequency/inverse-document-frequency weights plus seven extra calibration values; a row-count mismatch means the weights are incomplete or from an incompatible WeightFactory configuration.","triggerScenarios":"Calling recoverWeights(factory) where the database's weighttable row count differs from what the factory expects (factory.getIDFSize() + factory.getTFSize() + 7). Happens when the database was generated with a different BSim weight configuration (different number of structural features/categories) than the WeightFactory used to read it, or when the weighttable was partially written.","commonSituations":"Loading weights from a BSim database built with a different feature-vector layout (different IDF/TF dimensions). Version mismatch between the database's weight set and the client's WeightFactory. Interrupted weight-generation leaving an incomplete weighttable. Mixing databases of incompatible BSim configurations.","solutions":["Ensure the WeightFactory configuration (IDF/TF sizes) matches the one used to generate the database's weights.","Regenerate the database's weights with the current WeightFactory if the configuration changed.","Verify the BSim database version/layout matches the client before loading weights.","If generation was interrupted, re-run the weight-computation pass to complete the weighttable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the WeightFactory dimensions match the database before recovering.\nint expected = factory.getIDFSize() + factory.getTFSize() + 7;\nint actual = countWeightRows(db); // SELECT COUNT(*) FROM weighttable\nif (actual != expected) {\n    throw new IllegalStateException(\n        \"weighttable rows (\" + actual + \") != factory expected (\" + expected + \")\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a WeightFactory configuration matching the database's generation config.","Regenerate weights whenever the feature-vector layout changes.","Match BSim database version/layout to the client before loading weights."],"tags":["bsim","database","weights","configuration-mismatch","version-mismatch","sql-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}