{"record":{"id":"bf8e4e531e5889a9","repo":"NationalSecurityAgency/ghidra","slug":"block-model-not-found-modelname","errorCode":null,"errorMessage":"Block model not found: \" + modelName","messagePattern":"Block model not found: \" \\+ modelName","errorType":"exception","errorClass":"NotFoundException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/blockmodel/BlockModelServicePlugin.java","lineNumber":414,"sourceCode":"\n\t/**\n\t * @see ghidra.app.services.BlockModelService#getNewModelByName(java.lang.String, ghidra.program.model.listing.Program, boolean)\n\t */\n\t@Override\n\tpublic CodeBlockModel getNewModelByName(String modelName, Program program,\n\t\t\tboolean includeExternals) throws NotFoundException {\n\t\tif (program == null) {\n\t\t\treturn null;\n\t\t}\n\t\tBlockModelInfo info = basicModelsByName.get(modelName);\n\t\tif (info != null) {\n\t\t\treturn getModelInstance(info.modelClass, program, includeExternals);\n\t\t}\n\t\tinfo = subroutineModelsByName.get(modelName);\n\t\tif (info != null) {\n\t\t\treturn getModelInstance(info.modelClass, program, includeExternals);\n\t\t}\n\t\tthrow new NotFoundException(\"Block model not found: \" + modelName);\n\t}\n\n\t/**\n\t * @see ghidra.app.services.BlockModelService#getAvailableModelNames(int)\n\t */\n\t@Override\n\tpublic String[] getAvailableModelNames(int modelType) {\n\n\t\tTreeMap<String, BlockModelInfo> models =\n\t\t\t(modelType == BASIC_MODEL) ? basicModelsByName : subroutineModelsByName;\n\t\tString defaultModelName =\n\t\t\t(modelType == BASIC_MODEL) ? DEFAULT_BLOCK_MODEL_NAME : DEFAULT_SUBROUTINE_MODEL_NAME;\n\n\t\tArrayList<String> list = new ArrayList<>();\n\t\tfor (String modelName : models.keySet()) {\n\t\t\tif (modelName.equals(defaultModelName)) {\n\t\t\t\tlist.add(0, modelName);\n\t\t\t}","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/blockmodel/BlockModelServicePlugin.java#L396-L432","documentation":"Thrown by BlockModelServicePlugin.getNewModelByName() when the requested modelName is not found in either the basic-models map or the subroutine-models map. Both maps are case-sensitive TreeMaps populated in the plugin constructor with a fixed set of names plus any dynamically registered via registerModel(). The fixed names are: 'Simple Block' (basic), and 'Multiple Entry', 'Overlapped Code', 'Isolated Entry', 'Partitioned Code' (subroutine).","triggerScenarios":"Calling blockModelService.getNewModelByName(modelName, program, ...) with a name that is misspelled, has wrong case (the maps are case-sensitive), or is not among the registered models. Also when a previously-registered model has been unregistered via unregisterModel().","commonSituations":"Hardcoded model name from an older or newer Ghidra version where a constant changed; using a class name or display label instead of the registered model NAME constant (e.g. passing \"SimpleBlockModel\" instead of \"Simple Block\"); case mismatch such as \"simple block\" vs \"Simple Block\"; calling before a dynamically-registered model exists.","solutions":["List the valid names first: Arrays.toString(service.getAvailableModelNames(BlockModelService.ANY_BLOCK)) and use an exact, case-correct value from that list.","Reference the NAME constant of the model class instead of a string literal, e.g. SimpleBlockModel.NAME (\"Simple Block\") or MultEntSubModel.NAME (\"Multiple Entry\").","If you only need a working model, prefer getActiveBlockModel(program) / getActiveSubroutineModel(program) which never throw NotFoundException.","If a custom model is required, register it with service.registerModel(modelClass, modelName) before requesting it by name."],"exampleFix":"// before - hardcoded, wrong-case literal\nCodeBlockModel m = service.getNewModelByName(\"simple block\", program);\n// -> NotFoundException: Block model not found: simple block\n\n// after - use the registered NAME constant (exact, case-correct)\nCodeBlockModel m = service.getNewModelByName(SimpleBlockModel.NAME, program);\n// or guard by listing available names:\nString[] names = service.getAvailableModelNames(BlockModelService.BASIC_MODEL);\nCodeBlockModel m = java.util.Arrays.asList(names).contains(modelName)\n    ? service.getNewModelByName(modelName, program)\n    : service.getActiveBlockModel(program);","handlingStrategy":"validation","validationCode":"// Validate modelName against the service's own list before requesting it.\nimport ghidra.app.services.BlockModelService;\nString[] basic = service.getAvailableModelNames(BlockModelService.BASIC_MODEL);\nString[] sub   = service.getAvailableModelNames(BlockModelService.SUBROUTINE_MODEL);\njava.util.Set<String> valid = new java.util.HashSet<>();\njava.util.Collections.addAll(valid, basic);\njava.util.Collections.addAll(valid, sub);\nif (!valid.contains(modelName)) {\n    // pick the active model instead of throwing\n    return service.getActiveBlockModel(program);\n}\nreturn service.getNewModelByName(modelName, program);","typeGuard":null,"tryCatchPattern":"// Recommended: validate first (see validationCode). If you must call\n// directly, narrow the catch and fall back to the active model.\ntry {\n    return service.getNewModelByName(modelName, program);\n} catch (ghidra.util.exception.NotFoundException e) {\n    // modelName unknown; degrade to active model rather than crashing.\n    // Do NOT loop/retry the same name.\n    return service.getActiveBlockModel(program);\n}","preventionTips":["Never hardcode a model name string; use the model class's NAME constant (e.g. SimpleBlockModel.NAME).","Remember the registered names are case-sensitive: 'Simple Block', 'Multiple Entry', 'Overlapped Code', 'Isolated Entry', 'Partitioned Code'.","Prefer getActiveBlockModel/getActiveSubroutineModel when you do not need a specific named model.","Register custom models with registerModel() before any code requests them by name."],"tags":["ghidra","block-model","lookup","not-found","config","case-sensitivity"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}