{"record":{"id":"3255322fdd5d26cb","repo":"NationalSecurityAgency/ghidra","slug":"query-cannot-be-function-staged","errorCode":null,"errorMessage":"Query cannot be function staged","messagePattern":"Query cannot be function staged","errorType":"exception","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/FunctionStaging.java","lineNumber":46,"sourceCode":"\tprivate DescriptionManager gmanage;\t\t// The global function manager\n\tprivate DescriptionManager imanage;\t\t// The internal function manager\n\n\tpublic FunctionStaging(int stagesize) {\n\t\tthis.stagesize = stagesize;\n\t\tlocalQuery = null;\n\t}\n\n\t@Override\n\tpublic BSimQuery<?> getQuery() {\n\t\treturn localQuery;\n\t}\n\n\t@Override\n\tpublic boolean initialize(BSimQuery<?> q) throws LSHException {\n\t\tglobalQuery = q;\n\t\tgmanage = q.getDescriptionManager();\n\t\tif (gmanage == null)\n\t\t\tthrow new LSHException(\"Query cannot be function staged\");\n\t\ttotalsize = gmanage.numFunctions();\n\t\tqueriesmade = 0;\n\t\tlocalQuery = q.getLocalStagingCopy();\n\t\timanage = localQuery.getDescriptionManager();\n\n\t\tcuriter = gmanage.listAllFunctions();\n\t\timanage.clear();\n\t\timanage.transferSettings(gmanage);\n\t\tint count;\n\t\tfor (count = 0; count < stagesize; ++count) {\n\t\t\tif (!curiter.hasNext())\n\t\t\t\tbreak;\n\t\t\timanage.transferFunction(curiter.next(), true);\t// Copy the next function into manager for this stage\n\t\t\tqueriesmade += 1;\n\t\t}\n\t\treturn (count != 0);\n\t}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/FunctionStaging.java#L28-L64","documentation":"Thrown by FunctionStaging.initialize when the BSimQuery passed to it has a null DescriptionManager (q.getDescriptionManager() returns null). FunctionStaging splits a large query into batches by copying function descriptions from the global manager into per-stage local copies. Without a DescriptionManager, there are no function descriptions to stage, so the query type is incompatible with function-level staging.","triggerScenarios":"Calling FunctionStaging.initialize with a BSimQuery subclass whose getDescriptionManager() returns null. Not all BSimQuery types carry a DescriptionManager — query types that don't involve function metadata (e.g., QueryInfo, CreateDatabase, InstallTagRequest, PasswordChange) return null. Attempting to function-stage these is a programming error.","commonSituations":"A caller incorrectly wraps a non-function query (like QueryInfo or CreateDatabase) in a FunctionStaging manager, expecting it to batch by functions; a code path that generically applies FunctionStaging to any BSimQuery without checking whether the query type supports function staging.","solutions":["Only use FunctionStaging with query types that carry function descriptions (QueryNearest, QueryName, InsertRequest, etc.). Check q.getDescriptionManager() != null before creating the FunctionStaging.","Use the appropriate staging strategy for the query type — not all queries need or support function staging.","Add a guard in the caller: if (q.getDescriptionManager() == null) skip staging or use a different StagingManager.","Review the BSimQuery hierarchy to understand which subclasses override getDescriptionManager() with a non-null return."],"exampleFix":"// before\npublic boolean initialize(BSimQuery<?> q) throws LSHException {\n    globalQuery = q;\n    gmanage = q.getDescriptionManager();\n    if (gmanage == null)\n        throw new LSHException(\"Query cannot be function staged\");\n    ...\n}\n\n// caller fix\n// before:\n//   FunctionStaging staging = new FunctionStaging(20);\n//   staging.initialize(anyQuery);\n\n// after:\n//   if (anyQuery.getDescriptionManager() != null) {\n//       FunctionStaging staging = new FunctionStaging(20);\n//       staging.initialize(anyQuery);\n//   } else {\n//       // use non-staged execution\n//   }","handlingStrategy":"validation","validationCode":"// Check whether the query supports function staging before creating FunctionStaging\nif (q.getDescriptionManager() == null) {\n    throw new IllegalArgumentException(\n        \"Query type \" + q.getClass().getSimpleName() +\n        \" does not support function staging (no DescriptionManager).\");\n}\nFunctionStaging staging = new FunctionStaging(20);\nstaging.initialize(q);","typeGuard":"public static boolean supportsFunctionStaging(BSimQuery<?> q) {\n    return q != null && q.getDescriptionManager() != null;\n}","tryCatchPattern":"// No retry possible — this is a type incompatibility.\n// Validate before staging and fall back to non-staged execution.\nif (supportsFunctionStaging(query)) {\n    FunctionStaging staging = new FunctionStaging(stagesize);\n    staging.initialize(query);\n    // staged execution\n} else {\n    // Execute without staging\n    query.execute(querydb);\n}","preventionTips":["Check q.getDescriptionManager() != null before wrapping any BSimQuery in FunctionStaging.","Only use FunctionStaging with query types that involve function descriptions (QueryNearest, QueryName, InsertRequest, etc.).","Review the BSimQuery class hierarchy to understand which subclasses provide a DescriptionManager.","Add a guard in generic code paths that apply staging to arbitrary BSimQuery instances."],"tags":["bsim","staging","type-mismatch","query-protocol"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}