{"record":{"id":"048b7ed56de90bc2","repo":"NationalSecurityAgency/ghidra","slug":"error-querying-vectorid-048b7e","errorCode":null,"errorMessage":"Error querying vectorid: ","messagePattern":"Error querying vectorid: ","errorType":"exception","errorClass":"ElasticException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java","lineNumber":950,"sourceCode":"\t\t\tsimilarityResult.setTotalCount((int) queryNearestVector(resultset, vector, query.thresh,\n\t\t\t\tquery.signifthresh, vectormax));\n\n\t\t\t// Put the new results in the map so we can use them if another \n\t\t\t// similar vector comes along.\n\t\t\tvecToResultsMap.put(vector, resultset);\n\t\t}\n\n\t\tint count = 0;\n\n\t\tfor (VectorResult dresult : resultset) {\n\t\t\tif (count >= query.max) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfinal SignatureRecord srec = manager.newSignature(dresult.vec, dresult.hitcount);\n\t\t\tJsonArray descres;\n\t\t\tdescres = queryVectorIdMatch(dresult.vectorid, filter, query.max - count);\n\t\t\tif (descres == null) {\n\t\t\t\tthrow new ElasticException(\n\t\t\t\t\t\"Error querying vectorid: \" + Long.toString(dresult.vectorid));\n\t\t\t}\n\t\t\tif (descres.size() == 0) {\n\t\t\t\tif (filter != null) {\n\t\t\t\t\tcontinue; // Filter may have eliminated all results\n\t\t\t\t}\n\t\t\t\t// Otherwise this is a sign of corruption in the database\n\t\t\t\tthrow new ElasticException(\n\t\t\t\t\t\"No functions matching vectorid: \" + Long.toString(dresult.vectorid));\n\t\t\t}\n\t\t\tcount += descres.size();\n\t\t\tconvertDescriptionRows(similarityResult, descres, dresult, manager, srec);\n\t\t}\n\t}\n\n\t/**\n\t * Perform a full QueryNearest request, with additional filters, placing SimilarityResults\n\t * in the ResponseNearest object. An iterator to FunctionDescriptions determines what","sourceCodeStart":932,"sourceCodeEnd":968,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java#L932-L968","documentation":"Thrown in queryNearest when queryVectorIdMatch returns null for a given vector id. This is a defensive guard: in the current implementation queryVectorIdMatch (line 776) never returns null — it returns an empty JsonArray when total==0, or a non-null hitsArray otherwise, or throws an ElasticException on connection failure. The check is effectively unreachable dead code.","triggerScenarios":"Would only trigger if queryVectorIdMatch were modified in a fork to return null on some code path. As written, queryVectorIdMatch either returns a JsonArray (possibly empty) or propagates an ElasticException from connection.executeStatement.","commonSituations":"Not expected to occur with the shipped code. If observed, it indicates a custom modification to queryVectorIdMatch that introduced a null return path.","solutions":["Treat this as a code-defect signal: inspect queryVectorIdMatch for any branch that could return null, especially in a custom fork.","If using the stock Ghidra code, report as a bug since the guard is unreachable and queryVectorIdMatch should be audited for contract compliance.","As a workaround, ensure queryVectorIdMatch always returns a non-null JsonArray before reaching this call site."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    database.query(queryNearest);\n} catch (ElasticException e) {\n    if (e.getMessage().startsWith(\"Error querying vectorid:\")) {\n        // Defensive guard — should not occur in stock code; report as a bug\n        Msg.error(this, \"Unexpected null from queryVectorIdMatch — possible code regression: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["If using a custom fork, ensure queryVectorIdMatch never returns null — always return an empty JsonArray.","In stock Ghidra, treat this error as a signal to audit queryVectorIdMatch for contract violations.","Add unit tests asserting queryVectorIdMatch returns non-null for all code paths."],"tags":["bsim","query","dead-code","defensive-guard","unreachable"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}